<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--Log设定-->
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0" />
</configSections>
<log4net>
<!--日志记录器logger,可以有多个-->
<logger name="fileLog">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</logger>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="[%d][%-4p] %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender" >
<!--log存放的路径-->
<param name="File" value="log_" />
<param name="AppendToFile" value="true" />
<param name="StaticLogFileName" value="false"/>
<param name="MaximumFileSize" value="10MB"/>
<param name="Threshold" value="ALL"></param>
<param name="DatePattern" value="yyyyMM"\\log_"yyyyMMdd".log""/>
<param name="RollingStyle" value="Composite"/>
<param name="CountDirection" value="1"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="[%d][%-4p] %m%n" />
</layout>
</appender>
</log4net>
</configuration>
RollingLogFileAppender(文件记录)参数:< xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" />
参数名 | 描述 | ||||||||||||||||||||
filter | 可以有0或多个filter,具体配置在下面的Filter项说明。 | ||||||||||||||||||||
layout | 可以有0或者说1个layout,当没有layout时,没有输出。具体配置在下面的layout项说明 | ||||||||||||||||||||
param | Param有多个可以进行配置,常用的:
例如: <param name="File" value="UpLoads\\Log\\"/> <param name="MaximumFileSize" value="3000"/> <param name="StaticLogFileName" value="false"/> <param name="Threshold" value="Debug"></param> <param name="DatePattern" value="yyyyMM"\\#{ServerHostName}-"yyyyMMdd".log""/> <param name="RollingStyle" value="Date"/> |
<log4net>
<logger name="paylog">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
</logger>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<!--#交易日志文件存放位置-->
<param name="File" value="E:/logs/"/>
<param name="AppendToFile" value="true"/>
<param name="rollingStyle" value="Size"/>
<param name="maximumFileSize" value="2048KB"/>
<param name="DatePattern" value="yyyy-MM-dd/"mall.log"" />
<param name="StaticLogFileName" value="false"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
</log4net>