我读过这篇文章。而这个answer1SO,answer2SO,answer3SO。
到目前为止我所做的:
1. 在 AssemblyInfo.cs 的最后一行声明:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
2.写在app.config中
<?xml version="1.0" encoding="utf-8" ?>
<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>
</configuration>
3. 我在处理程序中写的内容:
private void btn_Click(object sender, RoutedEventArgs e)
{
XmlConfigurator.Configure();
ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
Log.Fatal("The exception occurred", new Exception("Hello World of event log"));
}`