详情请参照官网:http://logging.apache.org/log4net/release/config-examples.html
按照日志文件的大小来分割日志:
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<log4net>
<logger name="loggerAX">
<!--control log level: ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF-->
<level value="ALL" />
<appender-ref ref="RollingFileAppender"></appender-ref>
</logger>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<!--日志文件的绝对路径-->
<file value="D:\\system.log" />
<!-- 允许多个线程写入日志-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<!-- 按照文件的大小进行日志切换 -->
<rollingStyle value="Size" />
<staticLogFileName value="false" />
<!--单个日志文件的最大容量,此处单位可以KB、MB、GB等 -->
<maximumFileSize value="3MB" />
<!-- 保留log文件的数量,超出后删除-->
<MaxSizeRollBackups value="3" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref ="RollingFileAppender" />
</root>
</log4net>
</configuration>
按照日期分割时将
<rollingStyle value="Size" />
替换成
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd-HHmm" />
并删除
<maximumFileSize value="3MB" />