using log4net;using System;using System.Diagnostics;namespace MxWeiXinPF.Common.log{ public static class LogHelper { // private static LogMessage message = null; #region error 错误、异常时候记录日志 ////// 错误、异常时候记录日志 /// /// public static void Error(object message) { LogManager.GetLogger(GetCurrentMethodFullName()).Error(message); } ////// 错误、异常 记录日志 /// /// /// public static void Error(object message, Exception exception) { LogManager.GetLogger(GetCurrentMethodFullName()).Error(message, exception); } ////// 错误、异常 记录日志 /// /// 记录内容 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Error(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Error(lm); } ////// 错误、异常 记录日志 /// /// 记录内容 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Error(string message, Exception exception, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Error(lm, exception); } #endregion #region info 请求,用户行为 记录日志 ////// 请求,用户行为 记录日志 /// /// public static void Info(object message) { LogManager.GetLogger(GetCurrentMethodFullName()).Info(message); } ////// 请求,用户行为 记录日志 /// /// /// public static void Info(object message, Exception ex) { LogManager.GetLogger(GetCurrentMethodFullName()).Info(message, ex); } ////// 请求,用户行为 记录日志 /// /// 记录内容 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Info(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Info(lm); } ////// 请求,用户行为 记录日志 /// /// 记录内容 /// 异常 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Info(string message, Exception ex, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Info(lm, ex); } #endregion #region debug 调试记录日志 ////// 调试记录日志 /// /// public static void Debug(object message) { LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message); } ////// 调试记录日志 /// /// /// public static void Debug(object message, Exception ex) { LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message, ex); } ////// 调试记录日志 /// /// 记录内容 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Debug(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Debug(lm); } #endregion #region warin 警告 public static void Warn(object message) { LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message); } public static void Warn(object message, Exception ex) { LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message, ex); } ////// 错误、异常 记录日志 /// /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip /// 记录内容 public static void Warn(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Warn(lm); } ////// 错误、异常 记录日志 /// /// 记录内容 /// userid /// 平台 /// 模块 /// 操作行为 /// 值 /// ip public static void Warn(string message, Exception exception, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "") { LogMessage lm = new LogMessage(); lm.userid = userid; lm.platName = platName; lm.module = module; lm.operating = operating; lm.flgValue = flgValue; lm.addip = Utils.getIPAddress(); lm.remark = message; LogManager.GetLogger(GetCurrentMethodFullName()).Warn(lm, exception); } #endregion private static string GetCurrentMethodFullName() { StackFrame frame; string MethodFunStr = ""; string MethodFullNameStr = ""; // bool flag; try { int num = 2; StackTrace stackTrace = new StackTrace(); int length = stackTrace.GetFrames().Length; //do //{ int num1 = num; // num = num1 + 1; frame = stackTrace.GetFrame(num1); MethodFunStr = frame.GetMethod().DeclaringType.ToString(); // flag = (!MethodFunStr.EndsWith("Exception") ? false : num < length); //} //while (flag); string name = frame.GetMethod().Name; MethodFullNameStr = string.Concat(MethodFunStr, ".", name); } catch (Exception ex) { string exMessage = ex.Message; MethodFullNameStr = exMessage.Substring(0, exMessage.Length > 200 ? 200 : exMessage.Length); LogManager.GetLogger("内部调试").Error("GetCurrentMethodFullName()方法报错啦!!!", ex); } return MethodFullNameStr; // return "TestName"; } }}
log4net.config文件