/// <summary> /// 记录警告 /// </summary> public static void LogWarn(AppOpLog opLog) { if (log.IsWarnEnabled) { log.Warn(opLog); } }
/// <summary> /// 记录严重错误 /// </summary> public static void LogFatal(AppOpLog opLog, Exception ex) { if (log.IsFatalEnabled) { log.Fatal(opLog, ex); } }
/// <summary> /// 记录一般日志 /// </summary> public static void LogInfo(AppOpLog opLog) { if (log.IsInfoEnabled) { log.Info(opLog); } }
/// <summary> /// 记录错误 /// </summary> public static void LogError(AppOpLog opLog, Exception ex) { if (log.IsErrorEnabled) { log.Error(opLog, ex); } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure( new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "\\log4net.config") ); AppOpLog opLog = new AppOpLog { UserPhone = "18888888888", IP = "192.124.0.0", ActionName = "action", ControllerName = "controller", ActionParam = "param", Url = "url", HttpHeader = "header", HttpMethod = "get", UserAgent = "useragent", StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") }; opLog.RunTime = (Convert.ToDateTime(opLog.EndTime) - Convert.ToDateTime(opLog.StartTime)).TotalSeconds.ToString(); LogHelper.LogInfo(opLog); Console.ReadKey(); }