log4net實用配置代碼
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> <log4net> <root name="loginfo"> <level value="ALL" /> <appender-ref ref="InfoAppender" /> </root> <appender name="InfoAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="Log\\" /> <param name="AppendToFile" value="true" /> <param name="MaxFileSize" value="10240" /> <param name="MaxSizeRollBackups" value="100" /> <param name="StaticLogFileName" value="false" /> <param name="DatePattern" value="yyyyMMdd".txt"" /> <param name="RollingStyle" value="Date" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%n日志時間:%d [%t] %n日志級別:%-5p %n 內容:%m %n" /> </layout> </appender> </log4net> </configuration>
//接下來代碼注冊log4net
log4net.Config.XmlConfigurator.Configure();