public static void LogError(string message, Exception ex, Dictionary <string, string> parameters, bool isErrorLog, string childLogDirectory = "") { StringBuilder stringBuilder = new StringBuilder(); LoginfoEntity loginfoEntity = new LoginfoEntity(); loginfoEntity.Type = ((isErrorLog && ex != null) ? LogType.Error : LogType.Warn); loginfoEntity.ChildLogDirectory = childLogDirectory; loginfoEntity.Parameters = parameters; stringBuilder.AppendLine(message); if (!IsEnableLogging(loginfoEntity.Type)) { return; } if (ex != null) { if (!string.IsNullOrEmpty(ex.Message)) { stringBuilder.AppendLine($"错误描述:{ex.Message}"); } if (ex.InnerException != null) { stringBuilder.AppendLine($"内部异常:{ex.InnerException}"); } if (!string.IsNullOrEmpty(ex.StackTrace)) { stringBuilder.AppendLine($"异常跟踪:{ex.StackTrace}"); } } loginfoEntity.Message = stringBuilder.ToString(); ThreadPool.QueueUserWorkItem(new WaitCallback(LogToFile), loginfoEntity); }
public static void LogInfo(string message, LogType type, Dictionary <string, string> parameters = null, string childLogDirectory = "") { if (!IsEnableLogging(type)) { return; } LoginfoEntity loginfoEntity = new LoginfoEntity(); loginfoEntity.Message = message; loginfoEntity.Type = type; loginfoEntity.ChildLogDirectory = childLogDirectory; loginfoEntity.Parameters = parameters; ThreadPool.QueueUserWorkItem(new WaitCallback(LogToFile), loginfoEntity); }
private static string GetLogInfo(LoginfoEntity entity) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss,fff")); stringBuilder.Append(" "); stringBuilder.Append(entity.Message); if (entity.Parameters != null && entity.Parameters.Keys.Count > 0) { foreach (string current in entity.Parameters.Keys) { stringBuilder.AppendLine($"{current}:{entity.Parameters[current]}"); } } return(stringBuilder.ToString()); }