This works for me:
public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AttachConsole(int dwPr
ColoredConsoleAppender calls Console.OpenStandardOutput() in ActivateOptions to
store a Stream that represents the console. When you create a console in a
WinForm app you need to call ActivateOptions again so the internal Stream can
be re-initialized:
public partial class Form1 : Form
{
[Dl
Well, I tried this and it still does not work:
if (AllocConsole())
AttachConsole(-1);
// this file exists
XmlConfigurator.ConfigureAndWatch(new
System.IO.FileInfo("./Log4Net.config"));
LogManager.GetLogger("DebugLogger").Debug("
I am out of the office until 06/07/2009.
I will respond to your message when I return.
If you are experiencing a problem that requires urgent assistance please
contact the IT Service Desk (6634).
Note: This is an automated response to your message "Problem using a
ConsoleAppender in a Window
thx for your answer ! i'll try that but then I need to change my approach.
Originally I wanted to attach a console depending on log4net config, so now
i will try to detach the console depending on the config ;)
I don't mind doing that
I'll let you know if it works.
2009/6/26 Radovan Raszka
>
Hello,
try to allocate your console _before_ log4net is configured.
Radovan
Od: Michael SALOMON [mailto:michaelsalomo...@gmail.com]
Odesláno: 26. června 2009 15:22
Komu: log4net-user@logging.apache.org
Předmět: Problem using a ConsoleAppender in a Windows Form app
Hi !
I'm using log4net 1.2.10.0 and .NET 2.0
I wrote a Windows Form application and I want to be able to log debug
messages in a ColoredConsoleAppender (or whatever type of Console appender).
If I compile my application as a Console Application, this works fine... If
I compile it as a Windows Fo