/// <summary> /// 正式写入日志到Redis /// </summary> /// <typeparam name="TState">泛型</typeparam> /// <param name="logLevel">日志等级</param> /// <param name="eventId">日志触发事件</param> /// <param name="state">泛型实体</param> /// <param name="exception">异常信息</param> /// <param name="formatter">格式化处理</param> public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } var msg = $"日志触发ID:{eventId.Id},日志名:{eventId.Name},具体》》" + formatter(state, exception); switch (logLevel) { case LogLevel.Trace: case LogLevel.Debug: SystemLogHelper.Debug(moduleName, msg, exception); break; case LogLevel.Information: SystemLogHelper.Info(moduleName, msg, exception); break; case LogLevel.Warning: SystemLogHelper.Warn(moduleName, msg, exception); break; case LogLevel.Error: SystemLogHelper.Error(moduleName, msg, exception); break; case LogLevel.Critical: SystemLogHelper.Fatal(moduleName, msg, exception); break; default: break; } }
/// <summary> /// 输出Debug的日志提示 /// </summary> /// <param name="message">日志提示消息</param> /// <param name="isWriteLog">是否需要记录到系统日志,默认需要</param> public void Debug(string message, bool isWriteLog = true) { showLog(message + $"---{DateTime.Now} ThreadId:{Thread.CurrentThread.ManagedThreadId}\r\n", Color.Black); if (isWriteLog) { SystemLogHelper.Debug(MethodBase.GetCurrentMethod(), message); } }