/// <summary> /// 系统日志 对try块进行了封装,有返回值 /// </summary> /// <param name="type"></param> /// <param name="function">方法名称</param> /// <param name="errorHandel">异常处理方式</param> /// <param name="tryHandel">调试代码</param> /// <param name="catchHandel">异常处理方式</param> /// <param name="finallHandel">最终处理方式</param> public T Logger <T>(Type type, string function, Func <T> tryHandel, Func <Exception, T> catchHandel = null, Action finallHandel = null, ErrorHandel errorHandel = ErrorHandel.Continue) where T : new() { T res = LogHelper.Logger(type, function, errorHandel, tryHandel, catchHandel, finallHandel); return(res); }
public static T Logger <T>(Type type, string desc, ErrorHandel errorHandel, Func <T> tryHandel, Action <Exception> catchHandel = null, Action finallHandel = null) { ILog log = LogManager.GetLogger(type); try { //log.Debug(desc + "\r\n"); return(tryHandel()); } catch (Exception e) { #region 组装异常信息 LogMessage message = new LogMessage { OperationTime = DateTime.Now, Url = e.Source, Browser = NetHelper.Browser, Class = type.Namespace + type.FullName, Ip = NetHelper.Ip, Host = NetHelper.Host, ExceptionInfo = e.Message, ExceptionSource = e.Source, Content = desc }; string msg = LogFormat.ExceptionFormat(message); #endregion log.Error(msg); if (catchHandel != null) { catchHandel(e); } if (errorHandel == ErrorHandel.Throw) { throw; } } finally { if (finallHandel != null) { finallHandel(); } } return(default(T)); }
/// <summary> /// 系统日志 对try块进行了封装,无返回值 /// </summary> /// <param name="type"></param> /// <param name="function">方法名称</param> /// <param name="errorHandel">异常处理方式</param> /// <param name="tryHandel">调试代码</param> /// <param name="catchHandel">异常处理方式</param> /// <param name="finallHandel">最终处理方式</param> public void Logger(Type type, string argJsonString, string function, Action tryHandel, Action <Exception> catchHandel = null, Action finallHandel = null, ErrorHandel errorHandel = ErrorHandel.Continue) { LogHelper.Logger(type, argJsonString, function, errorHandel, tryHandel, catchHandel, finallHandel); }
///// <summary> ///// 系统日志 主动调用 ///// </summary> //private readonly LogHelper _logHelper = new LogHelper(MethodBase.GetCurrentMethod().DeclaringType); /// <summary> /// 系统日志 对try块进行了封装 /// </summary> /// <param name="type"></param> /// <param name="function">方法名称</param> /// <param name="errorHandel">异常处理方式</param> /// <param name="tryHandel">调试代码</param> /// <param name="catchHandel">异常处理方式</param> /// <param name="finallHandel">最终处理方式</param> public void Logger(Type type, string function, Action tryHandel, Action <Exception> catchHandel = null, Action finallHandel = null, ErrorHandel errorHandel = ErrorHandel.Throw) { LogHelper.Logger(type, function, errorHandel, tryHandel, catchHandel, finallHandel); }
public T Logger <T>(Type type, string desc, Func <T> tryHandel, Action <Exception> catchHandel = null, Action finallHandel = null, ErrorHandel errorHandel = ErrorHandel.Throw) { return(LogHelper.Logger <T>(type, desc, errorHandel, tryHandel, catchHandel, finallHandel)); }