應用log4net.dll
新建Global.asax,在cs文件中添加
protected void Application_Start(object sender, EventArgs e)
{
#region system log init
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\Log.config"));
#endregion
}
添加Log.config文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <root> <level value="Error"/> </root> <logger name="FatalLog"> <level value="Fatal"/> <appender-ref ref="RollingLogFileAppender"/> </logger> <logger name="ErrorLog"> <level value="Error"/> <appender-ref ref="RollingLogFileAppender"/> </logger> <logger name="WarnLog"> <level value="Warn"/> <appender-ref ref="RollingLogFileAppender"/> </logger> <logger name="DebugLog"> <level value="Debug"/> <appender-ref ref="RollingLogFileAppender"/> </logger> <logger name="HTGInfoLog"> <level value="Info"/> <appender-ref ref="RollingHTGFileAppender"/> </logger> <logger name="F4GInfoLog"> <level value="Info"/> <appender-ref ref="RollingF4GFileAppender"/> </logger> <logger name="InfoLog"> <level value="Info"/> <appender-ref ref="RollingLogFileAppender"/> </logger> <logger name="RuleEngineLog"> <level value="Info"/> <appender-ref ref="RollingRuleEngineLogFileAppender"/> </logger> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <!--輸出路徑--> <file value="Log\"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="1000"/> <param name="StaticLogFileName" value="false"/> <!--輸出按指定方式切換文件--> <param name="DatePattern" value="yyyyMMdd".log""/> <param name="RollingStyle" value="Composite"/><!--Date 按日期,Size 按大小--> <param name="maximumFileSize" value="10240KB" /> <!--輸出LOG格式--> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <param name="Header" value=""/> <param name="ConversionPattern" value="%n------------LogName:%c --------------------------------------------%nTimestamp: %d %nClient: %X%nThread:%thread%nLevel: %p%n%m %n-------------------------------------------------------------------------%n"/> <param name="Footer" value=""/> </layout> <!--輸出不同級別的LOG--> <!--<filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMin" value="DEBUG"/> <param name="LevelMax" value="FATAL"/> </filter>--> </appender> <appender name="RollingRuleEngineLogFileAppender" type="log4net.Appender.RollingFileAppender"> <!--Output path--> <file value="RuleEngineLog\"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="1000"/> <param name="StaticLogFileName" value="false"/> <!--Output file as specified switch--> <param name="DatePattern" value=""RuleEngineLog"yyyyMMdd".log""/> <param name="RollingStyle" value="Composite"/> <param name="maximumFileSize" value="10240KB" /> <!--LOG output format--> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <param name="Header" value=""/> <param name="ConversionPattern" value="%n------------LogName:%c--------------------------------------------%n%m %n-----------------------------------------------------------------------------%n"/> <param name="Footer" value=""/> </layout> </appender> </log4net> </configuration>
时间: 2024-10-25 13:41:04