1 <configSections> 2 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> 3 </configSections> 4 <!--具体的日志记录器配置--> 5 <log4net> 6 <root> 7 <level value="DEBUG"/> 8 <appender-ref ref="DefaultBankTradeAppender"/> 9 </root> 10 11 <logger name="BankTradeLogger"> 12 <!--这里不再设置记录级别,默认为root节点的级别--> 13 <appender-ref ref="DefaultBankTradeAppender"/> 14 </logger> 15 16 17 <logger name="BankBalanceQueryLogger"> 18 <level value="DEBUG"/> 19 <appender-ref ref="BankBalanceQueryLogAppender" /> 20 </logger> 21 22 <logger name="TransMoneyLogger"> 23 <appender-ref ref="Bank_QCHZ_LogAppender" /> 24 </logger> 25 26 <!--签约新用户--> 27 <logger name="BankQYXYHLogger"> 28 <appender-ref ref="Bank_QYXYH_LogAppender" /> 29 </logger> 30 31 <appender name="DefaultBankTradeAppender" type ="log4net.Appender.RollingFileAppender"> 32 <file value="BankLogs/bankLog.log" /> 33 <appendToFile value="true" /> 34 <rollingStyle value="Size" /> 35 <!--使用混合文件名格式,日期和大小--> 36 <maxSizeRollBackups value="10" /> 37 <maximumFileSize value="1024KB" /> 38 <layout type="log4net.Layout.PatternLayout"> 39 <param name="Footer" value=" ======================================== "/> 40 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> 41 </layout> 42 </appender> 43 44 <appender name="BankBalanceQueryLogAppender" type="log4net.Appender.RollingFileAppender"> 45 <file value="BankLogs/BalanceQuery.log" /> 46 <appendToFile value="true" /> 47 <rollingStyle value="Composite" /> 48 <!--使用混合文件名格式,日期和大小--> 49 <maxSizeRollBackups value="10" /> 50 <maximumFileSize value="10KB" /> 51 <DatePattern value=""_"yyyyMMdd".log"" /> 52 <layout type="log4net.Layout.PatternLayout"> 53 <param name="Footer" value=" ======================================= "/> 54 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> 55 </layout> 56 </appender> 57 58 <appender name="Bank_QCHZ_LogAppender" type="log4net.Appender.RollingFileAppender"> 59 <file value="BankLogs/QCHZ.log" /> 60 <appendToFile value="true" /> 61 <rollingStyle value="Composite" /> 62 <!--使用混合文件名格式,日期和大小--> 63 <maxSizeRollBackups value="10" /> 64 <maximumFileSize value="10KB" /> 65 <DatePattern value=""_"yyyyMMdd".log"" /> 66 <layout type="log4net.Layout.PatternLayout"> 67 <param name="Footer" value=" ======================================= "/> 68 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> 69 </layout> 70 </appender> 71 72 <appender name="Bank_QYXYH_LogAppender" type="log4net.Appender.RollingFileAppender"> 73 <file value="BankLogs/QYXYH.log" /> 74 <appendToFile value="true" /> 75 <rollingStyle value="Composite" /> 76 <!--使用混合文件名格式,日期和大小--> 77 <maxSizeRollBackups value="10" /> 78 <maximumFileSize value="10KB" /> 79 <DatePattern value=""_"yyyyMMdd".log"" /> 80 <layout type="log4net.Layout.PatternLayout"> 81 <param name="Footer" value=" ======================================= "/> 82 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> 83 </layout> 84 </appender> 85 86 </log4net>
Example usage:
1 // 在应用程序的配置文件中配置(App.Config) 2 [assembly: log4net.Config.XmlConfigurator(Watch=true)] 3 // This will cause log4net to look for a configuration file 4 // called TestApp.exe.config in the application base 5 // directory (i.e. the directory containing TestApp.exe) 6 // The config file will be watched for changes. 7 8 9 // 在单独的配置文件中配置选项 Configure log4net using the .log4net file 10 [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)] 11 // This will cause log4net to look for a configuration file 12 // called TestApp.exe.log4net in the application base 13 // directory (i.e. the directory containing TestApp.exe) 14 // The config file will be watched for changes. 15
记录下来,希望两周后还能记得!