标签:play ace source pen dmi time att reading mat
自己动手,丰衣足食
1、config文件
<?xml version="1.0" encoding="utf-8" ?> <!--日志记录配置--> <log4net debug="true"> <!--Level级别:OFF<DEBUG<INFO<WARN<ERROR<FATAL<ALL--> <!--配置输出介质--> <appender name="Console" type="log4net.Appender.ConsoleAppender"> <target value="Console.Error"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d [%t] %5l (%F:%L) - %m%n"/> </layout> </appender> <!--配置异常的文件输出介质--> <appender name="SystemErrorLog" type="log4net.Appender.RollingFileAppender,log4net"> <!--<file value="log/error/SYSTEM_ERROR_LOG"/>--> <file value="log/error/SYSTEM_ERROR_LOG"/> <appendToFile value="true"/> <datePattern value="yyyyMMdd".log""/> <StaticLogFileName value="false"/> <maxSizeRollBackups value="100"/> <rollingStyle value="Date"/> <encoding value="UTF-8"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-30d{yyyy/MM/dd zzz HH:mm:ss} [%t] %-5l [%ndc] - %m %e %n"/> </layout> </appender> <!--定义系统警告日志输出介质warn--> <appender name="SystemWarn" type="log4net.Appender.RollingFileAppender,log4net"> <file value="log/warn/SYSTEM_WARN_LOG"/> <appendToFile value="true"/> <datePattern value="yyyyMMdd".log""/> <StaticLogFileName value="false"/> <maxSizeRollBackups value="100"/> <rollingStyle value="Date"/> <encoding value="UTF-8"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-30d{yyyy/MM/dd zzz HH:mm:ss} [%t] %-5l %l [%ndc] - %m %e %n"/> </layout> </appender> <!--定义通知信息日志输出介质--> <appender name="SystemInforLog" type="log4net.Appender.RollingFileAppender,log4net"> <file value="log/infor/SYSTEM_INFOR_LOG"/> <appendToFile value="true"/> <datePattern value="yyyyMMdd".log""/> <StaticLogFileName value="false"/> <maxSizeRollBackups value="100"/> <rollingStyle value="Date"/> <encoding value="UTF-8"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-30d{yyyy/MM/dd HH:mm:ss} %m %l %n"/> </layout> </appender> <!--定义ADO方式记录系统日志--> <!--<appender name="AdminLogger" type="log4net.Appender.ADONetAppender"> <bufferSize value="20" /> <connectionType value="System.Data.SqlClient.SqlConnection,System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <connectionString value="Data Source=.;Initial Catalog=ACM;User ID=sa;Password=******" /> <commandText value="INSERT INTO [tb_AdminLog]([ActionType],[AdminID],[Event],[ActionLevel],[CreatedOn],[IP],[Msg]) VALUES(@ActionType,@AdminID,@Event,@ActionLevel,@CreatedOn,@IP,@Msg)" /> <parameter> <parameterName value="@ActionType" /> <dbType value="String" /> <size value="2" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{ActionType}" /> </layout> </parameter> <parameter> <parameterName value="@AdminID" /> <dbType value="Int32" /> <size value="10" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{AdminID}" /> </layout> </parameter> <parameter> <parameterName value="@Event" /> <dbType value="String" /> <size value="20" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{Event}" /> </layout> </parameter> <parameter> <parameterName value="@ActionLevel" /> <dbType value="String" /> <size value="10" /> <layout type="log4net.Layout.PatternLayout" > <conversionPattern value="%property{ActionLevel}" /> </layout> </parameter> <parameter> <parameterName value="@CreatedOn" /> <dbType value="DateTime" /> <layout type="log4net.Layout.RawTimeStampLayout" /> </parameter> <parameter> <parameterName value="@IP" /> <dbType value="String" /> <size value="15" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{IP}" /> </layout> </parameter> <parameter> <parameterName value="@Msg" /> <dbType value="String" /> <Size value="1000"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{Msg}" /> </layout> </parameter> </appender>--> <!--根日志对象--> <root> <!--配置根日志对象的访问级别--> <level value="DEBUG"/> <!--配置根日志对象的记录器--> <appender-ref ref="Console"/> <appender-ref ref="SystemErrorLog"/> </root> <!--错误信息记录器--> <logger name="SystemErrorLogger"> <level value="ERROR"/> <appender-ref ref="SystemErrorLog"/> </logger> <!--系统警告信息记录器--> <logger name="SystemWarn"> <level value="WARN"/> <appender-ref ref="SystemWarn"/> </logger> <!--系统通知信息记录器--> <logger name="SystemInforLog" additivity="false"> <level value="INFO"/> <appender-ref ref="SystemInforLog"/> </logger> <!--系统通知信息记录器--> <logger name="AdminLogger" additivity="false"> <level value="INFO"/> <appender-ref ref="AdminLogger"/> </logger> </log4net>
2、代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GCommon { public class logUtil { /// <summary> /// 系统错误日志 /// </summary> public static readonly log4net.ILog SystemErrorLogger = log4net.LogManager.GetLogger("SystemErrorLogger"); /// <summary> /// 系统通知 /// </summary> public static readonly log4net.ILog SystemInforLogger = log4net.LogManager.GetLogger("SystemInforLog"); /// <summary> /// 记录错误日志 /// </summary> /// <param name="message"></param> /// <param name="ex"></param> public static void Error(object message, Exception ex) { SystemErrorLogger.Error(message,ex); } /// <summary> /// 记录错误日志 /// </summary> /// <param name="message"></param> public static void Error(object message) { SystemErrorLogger.Error(message); } /// <summary> /// 错误日志 /// </summary> /// <param name="format"></param> /// <param name="parameters"></param> public static void ErrorFormat(string format, params object[] parameters) { SystemErrorLogger.ErrorFormat(format,parameters); } /// <summary> /// 信息日志 /// </summary> /// <param name="message"></param> public static void Info(object message) { SystemInforLogger.Info(message); } /// <summary> /// 信息日志 /// </summary> /// <param name="format"></param> /// <param name="parameters"></param> public static void Info(string format,params object[] parameters) { SystemInforLogger.InfoFormat(format,parameters); } } }
3、ConfigFile
[assembly: log4net.Config.XmlConfigurator(ConfigFile = @"config\logger.config", Watch = true)]
4、启动
protected void Application_Start(object sender, EventArgs e) { log4net.Config.XmlConfigurator.Configure(); }
标签:play ace source pen dmi time att reading mat
原文地址:http://www.cnblogs.com/shiyige-216/p/7700094.html