在Log4net中将控制台附加程序添加到Windows窗体 [英] Adding console appender to a windows form in log4net
问题描述
是否可以将控制台添加到基于表单的C#应用程序中? 目前,当我做类似的事情
Is it possible to add a console to a form based C# application ? Currently when I do something like
Console.WriteLine("testing");
它出现在VS2010的输出窗口中. 我想知道是否可以将控制台附加到我的Windows窗体应用程序中,以便输出显示在控制台中.
It appears in output window of the VS2010. I want to know if its possible to attach a console to my windows form application.So that the output appears in the console.
看来我的第一个问题有点误导,而且没有确切说明我想要完成的工作.我刚刚使用
Looks like my first question was a bit misleading and it did not exactly specify what I wanted to accomplish. I just added a console to my application using
[DllImport("kernel32")]
static extern int AllocConsole();
但是我真正想要的是log4net控制台附加程序的输出将显示在 该控制台没有发生. 我的附加程序的xml是
However what I really want is the output of log4net console appender to be displayed in that console which is not happening. The xml for my appender is
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="INFO" />
<foreColor value="White" />
<backColor value="Red, HighIntensity" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%class %date - %message %newline" />
</layout>
</appender>
现在我喜欢的时候
log.info("Some log");
它仍然不会在新添加的控制台窗口中显示.关于我该怎么做的任何建议?
It still does not display it in the newly added console window. Any suggestions on how i could do that ?
推荐答案
只需使您的项目成为控制台应用程序,然后从控制台应用程序创建/显示表单即可,而不是相反.
Just make your project a console application and create/show a form from the console application rather than the other way around.
这篇关于在Log4net中将控制台附加程序添加到Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!