log4net按照不同的级别输出到不同文件
配置目标:
1)一个文件记录全部级别的日志;
2)记录某一级别的日志(使用LevelRangeFilter进行级别的过滤)。
Eg:
- <log4net>
- <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
- <layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%d [%t] %-5p %l - %m%n %property{ServiceType}"/>
- </layout>
- </appender>
- <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
- <layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%d [%t] %-5p %l - %m%n"/>
- </layout>
- </appender>
- <appender name="RollingFileAppenderAll" type="log4net.Appender.RollingFileAppender">
- <param name="File" value="Log/alllLog.txt"/>
- <appendToFile value="true"/> <rollingStyle value="Composite"/>
- <datePattern value="yyyyMM"/>
- <maxSizeRollBackups value="100"/>
- <maximumFileSize value="2MB"/>
- <PreserveLogFileNameExtension value="true"/>
- <staticLogFileName value="false"/>
- <layout type="log4net.Layout.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p %m%n"/>
- </layout>
- </appender>
- <appender name="ErrorRollingFileAppender" type="log4net.Appender.RollingFileAppender" LEVEL="ERROR">
- <file value="Log/Error.txt" />
- <appendToFile value="true" />
- <rollingStyle value="Size" />
- <maxSizeRollBackups value="10" />
- <maximumFileSize value="1024KB" />
- <staticLogFileName value="true" />
- <layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%date [%thread] %-5level [%logger] [%property{NDC}] - %message%newline" />
- </layout>
- <filter type="log4net.Filter.LevelRangeFilter">
- <param name="LevelMin" value="ERROR" />
- <param name="LevelMax" value="ERROR" />
- </filter>
- </appender>
- <root>
- <level value="DEBUG"/>
- <appender-ref ref="ConsoleAppender"/>
- <appender-ref ref="RollingFileAppenderAll"/>
- <appender-ref ref="ErrorRollingFileAppender"/>
- </root>
- </log4net>