Пример #1
0
 /// <summary>
 /// 记录内部异常记录
 /// </summary>
 /// <param name="e">异常信息</param>
 /// <param name="remark">备注信息</param>
 /// <param name="logSpan">日志段</param>
 internal static void InnerException(Exception e, string remark, LogSpan logSpan)
 {
     Task.Run(() =>
     {
         try
         {
             ExceptionLog log = new ExceptionLog
             {
                 CustomerInfo  = new Dictionary <string, object>(),
                 LogSpan       = logSpan,
                 ExceptionInfo = e.ToString(),
                 LogLevel      = LogLevel.Error,
             };
             log.CustomerInfo.Add("Remark", string.IsNullOrWhiteSpace(remark) ? string.Empty : remark);
             if (!LogFilter(log.LogLevel))
             {
                 _logger.WriteException(log);
             }
         }
         catch (Exception ex)
         {
             InnerTxtLog.WriteException(ex, "记录异常日志异常,参数:" + new { e, remark }.ToJson());
         }
     });
 }
Пример #2
0
        /// <summary>
        /// 记录debug日志
        /// </summary>
        /// <param name="debugInfo">debug信息</param>
        /// <param name="args">请求参数</param>
        /// <param name="returnVal">返回参数</param>
        /// <param name="keyWord">自定义信息</param>
        public static void Debug(string debugInfo, object args = null, object returnVal = null, Dictionary <string, object> keyWord = null)
        {
            // 调用链+1
            LogSpan logSpan      = LogSpan.Extend(LogContext.Current);
            var     functionName = GetStackTrace();

            Task.Run(() =>
            {
                try
                {
                    LogBase log = new LogBase
                    {
                        CustomerInfo = keyWord ?? new Dictionary <string, object>(),
                        LogSpan      = logSpan,
                        LogLevel     = LogLevel.Warning,
                    };
                    log.LogSpan.FunctionName = functionName;
                    log.LogSpan.ParamIn      = args?.ToJson() ?? string.Empty;
                    log.LogSpan.ParamOut     = returnVal?.ToJson() ?? string.Empty;
                    log.CustomerInfo.Add("DebugInfo", string.IsNullOrWhiteSpace(debugInfo) ? string.Empty : debugInfo);
                    if (!LogFilter(log.LogLevel))
                    {
                        _logger.Write(log);
                    }
                }
                catch (Exception ex)
                {
                    InnerTxtLog.WriteException(ex, "记录Debug日志异常,参数:" + new { debugInfo, args, returnVal, keyWord }.ToJson());
                }
            });
        }
Пример #3
0
 /// <summary>
 /// 记录info信息
 /// </summary>
 /// <param name="logSpan">日志段</param>
 /// <param name="paramOut">内容</param>
 internal static void InnerInfo(LogSpan logSpan, string paramOut = "")
 {
     Task.Run(() =>
     {
         try
         {
             LogBase log = new LogBase
             {
                 CustomerInfo = new Dictionary <string, object>(),
                 LogSpan      = logSpan,
                 LogLevel     = LogLevel.Info,
             };
             log.LogSpan.ParamOut = paramOut;
             log.CustomerInfo.Add("Content", logSpan.FunctionName ?? string.Empty);
             if (!LogFilter(log.LogLevel))
             {
                 _logger.Write(log);
             }
         }
         catch (Exception ex)
         {
             InnerTxtLog.WriteException(ex, "记录内部Info日志异常,参数:" + new { paramOut, logSpan }.ToJson());
         }
     });
 }
Пример #4
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="e">异常信息</param>
        /// <param name="remark">备注</param>
        /// <param name="args">请求参数</param>
        /// <param name="returnVal">返回参数</param>
        /// <param name="keyWord">自定义信息</param>
        public static void Exception(Exception e, string remark, object args = null, object returnVal = null, Dictionary <string, object> keyWord = null)
        {
            // 调用链+1
            LogSpan logSpan      = LogSpan.Extend(LogContext.Current);
            var     functionName = GetStackTrace();

            Task.Run(() =>
            {
                try
                {
                    ExceptionLog log = new ExceptionLog
                    {
                        CustomerInfo  = keyWord ?? new Dictionary <string, object>(),
                        LogSpan       = logSpan,
                        ExceptionInfo = e.ToString(),
                        LogLevel      = LogLevel.Error,
                    };
                    log.LogSpan.FunctionName = functionName;
                    log.LogSpan.ParamIn      = args?.ToJson() ?? string.Empty;
                    log.LogSpan.ParamOut     = returnVal?.ToJson() ?? string.Empty;
                    log.CustomerInfo.Add("Remark", string.IsNullOrWhiteSpace(remark) ? string.Empty : remark);
                    if (!LogFilter(log.LogLevel))
                    {
                        _logger.WriteException(log);
                    }
                }
                catch (Exception ex)
                {
                    InnerTxtLog.WriteException(ex, "记录异常日志异常,参数:" + new { e, remark, args, returnVal, keyWord }.ToJson());
                }
            });
        }
Пример #5
0
 private static void IniLogger()
 {
     try
     {
         Assembly impAssembly     = Assembly.Load(LogConfig.LogProviderAssembly);
         var      logProviderType = impAssembly.GetType(LogConfig.LogProviderType);
         _logger = (ILog)Activator.CreateInstance(logProviderType);
     }
     catch (Exception e)
     {
         _logger = new TxtLogger();
         InnerTxtLog.WriteException(e, "初始化日志提供者异常");
     }
 }
Пример #6
0
 /// <summary>
 /// 记录内部运行日志
 /// </summary>
 internal static void InnerRunningLog(LogSpan logSpan)
 {
     Task.Run(() =>
     {
         try
         {
             LogBase log = new LogBase
             {
                 CustomerInfo = new Dictionary <string, object>(),
                 LogSpan      = logSpan,
                 LogLevel     = LogLevel.RunningLog,
             };
             if (!LogFilter(log.LogLevel))
             {
                 _logger.Write(log);
             }
         }
         catch (Exception ex)
         {
             InnerTxtLog.WriteException(ex, "记录运行日志异常,参数:" + logSpan.ToJson());
         }
     });
 }