1 <?xml version="1.0"?> 2 <configuration> 3 <configSections> 4 <!--log4net配置安装--> 5 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> 6 </configSections> 7 <log4net> 8 <!--记录器root可以被其他继承--> 9 <root> 10 <level value="All" /> 11 <appender-ref ref="LogFileAppender" /> 12 <appender-ref ref="ErrorFileAppender"/> 13 </root> 14 15 <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" LEVEL="INFO"> 16 <param name="File" value="Logs\info\"/> 17 <param name="AppendToFile" value="true"/> 18 <param name="DatePattern" value="yyyy-MM-dd.‘.txt‘"/> 19 <param name="RollingStyle" value="Date"/> 20 <param name="StaticLogFileName" value="false"/> 21 <layout type="log4net.Layout.PatternLayout"> 22 <param name="ConversionPattern" value="记录时间:%date 线程ID:[%thread] 日志级别:%-5level 类:%logger property:[%property{NDC}] - 描述:%message%newline" /> 23 </layout> 24 <filter type="log4net.Filter.LevelRangeFilter"> 25 <param name="LevelMin" value="INFO" /> 26 <param name="LevelMax" value="INFO" /> 27 </filter> 28 </appender> 29 30 <appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender" LEVEL="ERROR"> 31 <param name="File" value="Logs\error\"/> 32 <param name="AppendToFile" value="true"/> 33 <param name="DatePattern" value="yyyy-MM-dd.‘.txt‘"/> 34 <param name="RollingStyle" value="Date"/> 35 <param name="StaticLogFileName" value="false"/> 36 <layout type="log4net.Layout.PatternLayout"> 37 <param name="ConversionPattern" value="记录时间:%date 线程ID:[%thread] 日志级别:%-5level 类:%logger property:[%property{NDC}] - 描述:%message%newline"/> 38 </layout> 39 <filter type="log4net.Filter.LevelRangeFilter"> 40 <param name="LevelMin" value="ERROR" /> 41 <param name="LevelMax" value="ERROR" /> 42 </filter> 43 </appender> 44 45 </log4net> 46 <startup> 47 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 48 </startup> 49 </configuration>
log4net根据日志类型写入到不同的文件中
时间: 2024-11-05 22:56:51