我希望能够使用log4net登录Windows事件查看器。
我创建了一个控制台应用程序(.NET Framework 4),我添加了log4net.dll的引用,并将以下代码放置在我的App.config文件中:
它没有记录,什么都没有发生,为什么?
谢谢。
我创建了一个控制台应用程序(.NET Framework 4),我添加了log4net.dll的引用,并将以下代码放置在我的App.config文件中:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="EventLogAppender"/>
</root>
</log4net>
<startup><supportedRuntime version="v2.0.50727"/></startup>
</configuration>
我放置了以下代码:
class Program
{
static void Main(string[] args)
{
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
log.Error("test error", new Exception("error's exception", new Exception("error's innerexception")));
Console.Read();
}
}
它没有记录,什么都没有发生,为什么?
谢谢。