appender 附加器
RollingFileAppender 滚动文件appender
MaxSizeRollBackups 最大尺寸回滚
ConversionPattern 转换模式
LevelRangeFilter 电平范围滤波器
PatternLayout 图案布局
log4net配置在节点configuration下面
<log4net> <appender name="ErrorLog" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log\Error.Log.txt"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="10"/> <param name="MaximumFileSize" value="1MB"/> <param name="RollingStyle" value="Size"/> <param name="StaticLogFileName" value="true"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMax" value="ERROR"/> <param name="LevelMin" value="ERROR"/> </filter> </appender> <appender name="InfoLog" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log\Info.Log.txt"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="10"/> <param name="MaximumFileSize" value="1MB"/> <param name="RollingStyle" value="Size"/> <param name="StaticLogFileName" value="true"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMax" value="INFO"/> <param name="LevelMin" value="INFO"/> </filter> </appender> <appender name="DebugLog" type="log4net.Appender.RollingFileAppender"> <param name="File" value="log\Debug.Log.txt"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="10"/> <param name="MaximumFileSize" value="1MB"/> <param name="RollingStyle" value="Size"/> <param name="StaticLogFileName" value="true"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMax" value="DEBUG"/> <param name="LevelMin" value="DEBUG"/> </filter> </appender> <root> <level value="all"/> <appender-ref ref="InfoLog"/> <appender-ref ref="ErrorLog"/> <appender-ref ref="DebugLog"/> </root> </log4net>
configSections下面配置
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
时间: 2024-10-09 20:58:28