1.引用 log4net.dll
2.添加特性
添加如下代码
[assembly: log4net.Config.XmlConfigurator()]
3.在APP.config添加代码
<log4net>
<logger name="ServerLogError">
<level value="ALL" />
<appender-ref ref="ServerLogFileAppender" />
</logger>
<appender name="ServerLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\\LogError\\" />
<param name="DatePattern" value="yyyy-MM-dd".log"" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<maxSizeRollBackups value="100" />
<maximumFileSize value="10MB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date Error:%message%newline" />
</layout>
</appender>
</log4net>