public static void LogException(LogID logID, Exception ex) { var msg = $"{DateTime.Now:MM.dd HH:mm:ss} - {ex}{Environment.NewLine}"; WriteLineToConsole(msg, ConsoleColor.Red); WriteToFile(logID, msg); }
private static void WriteToFile(LogID logID, string msg) { try { lock (_logDir) { // allways add a NewLine if (!msg.EndsWith(Environment.NewLine)) { msg += Environment.NewLine; } var time = DateTime.UtcNow.ToString("MM.dd HH:mm:ss.fff - "); if (!msg.StartsWith(time)) { msg = time + msg; } // allways add timestamp. File.AppendAllText(GetFilename(logID), msg); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.WriteLine(msg); } }
public static void Fatal(string Message, LogID logID) { try { DiscordAPI.GetClient().Logger.Log(LogLevel.Critical, eventIDs[logID], Message); } catch (NullReferenceException) { Console.WriteLine("[CRITICAL] " + Message); } }
public static void Error(string Message, LogID logID) { try { DiscordAPI.GetClient().Logger.Log(LogLevel.Error, eventIDs[logID], Message); } catch (NullReferenceException) { Console.WriteLine("[ERROR] " + Message); } }
public static void Warn(string Message, LogID logID) { try { DiscordAPI.GetClient().Logger.Log(LogLevel.Warning, eventIDs[logID], Message); } catch (NullReferenceException) { Console.WriteLine("[WARNING] " + Message); } }
private static string GetFilename(LogID logID) { if (_nextSizeCheck == null) { InitDictionary(); } var filepath = Path.Combine(_logDir, logID.ToString() + ".log"); if (DateTime.Now > _nextSizeCheck[logID] && File.Exists(filepath)) { if (new FileInfo(filepath).Length > MaxLogSizeMB * 1024 * 1024) { File.Delete(filepath); } _nextSizeCheck[logID] = DateTime.Now.AddMinutes(1); } return(filepath); }
public static void LogError(LogID logID, string error, Exception ex) { error = DateTime.UtcNow.ToString("MM.dd HH:mm:ss.fff - ") + error; WriteToFile(logID, error + Environment.NewLine + ex.ToString() + Environment.NewLine); }
public static void LogErrorAndConsoleLn(LogID logID, string error) { error = DateTime.UtcNow.ToString("MM.dd HH:mm:ss.fff - ") + error; WriteLineToConsole(error, ConsoleColor.Red); WriteToFile(logID, error + Environment.NewLine); }
public static void LogColor(LogID logID, ConsoleColor color, string msg) { WriteLineToConsole(msg, color); WriteToFile(logID, msg); }
public static void LogInfoAndConsoleLn(LogID logID, string msg, Exception ex) { Console.WriteLine(msg); WriteToFile(logID, msg + Environment.NewLine + ex.ToString() + Environment.NewLine); }
public static void LogInfoAndConsoleLn(LogID logID, string msg) { Console.WriteLine(msg); WriteToFile(logID, msg + Environment.NewLine); }
public static void LogInfoAndConsole(LogID logID, string msg) { Console.Write(msg); WriteToFile(logID, msg); }
public static void LogData(LogID logID, string msg) { WriteToFile(logID, msg); }
public static void LogShow(this object obj, LogID id, string addStr = "") { obj.LogShow((int)id, addStr); }