コード例 #1
0
ファイル: LogManager.cs プロジェクト: thxu/TLog
 /// <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
ファイル: LogManager.cs プロジェクト: thxu/TLog
        /// <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
ファイル: LogManager.cs プロジェクト: thxu/TLog
 /// <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
ファイル: LogManager.cs プロジェクト: thxu/TLog
        /// <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
ファイル: LogManager.cs プロジェクト: thxu/TLog
 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
ファイル: LogManager.cs プロジェクト: thxu/TLog
 /// <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());
         }
     });
 }