1引用log4jNet.dll
2在AssemblyInfo.cs中增加
[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension = "config", Watch = true)]
3.1在App.config中在<configSections>节点中增加
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net-net-1.0"/>
3.2在<configuration>节点中增加<log4net>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
<param name="File" value="log-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
</log4net>
4.代码调用
log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
log.Debug("hello");