public static string GetIcon(LogStatus LogStatus) { if (icon.ContainsKey(LogStatus)) return icon[LogStatus]; switch (LogStatus.ToString().ToUpper()) { case "FAIL": return "times-circle-o"; case "ERROR": return "exclamation-circle"; case "FATAL": return "exclamation-circle"; case "PASS": return "check-circle-o"; case "INFO": return "info-circle"; case "WARNING": return "warning"; case "SKIP": return "chevron-circle-right"; default: return "question"; } }
private static void LogToFile(string pLog, LogStatus pStatus) { string LogPath = @"C:\ComCon\Log\Log_" + DateTime.Today.Date + ".txt"; TextWriter tw = new StreamWriter(LogPath, true); tw.Write("[" + pStatus.ToString("G") + "]" + pLog); tw.Close(); }
public static string GetIcon(LogStatus LogStatus) { if (icon.ContainsKey(LogStatus)) { return(icon[LogStatus]); } switch (LogStatus.ToString().ToUpper()) { case "FAIL": return("times-circle-o"); case "ERROR": return("exclamation-circle"); case "FATAL": return("exclamation-circle"); case "PASS": return("check-circle-o"); case "INFO": return("info-circle"); case "WARNING": return("warning"); case "SKIP": return("chevron-circle-right"); default: return("question"); } }
public static void Log(LogStatus status, string message, [CallerMemberName] string source = null) { if (Application.Current == null) { return; } Application.Current.Dispatcher.Invoke( () => Logs.MainLog.Items.Add(new LogItem { Status = status.ToString(), Source = source, Message = message })); }
/// <summary> /// Write a message to the console. /// </summary> /// <param name="str">The string to write.</param> /// <param name="status">The severity / type of the message.</param> public static void Write(string str, LogStatus status = LogStatus.General) { string formattedStr = "[" + DateTime.Now.ToString() + "] [" + status.ToString() + "] " + str; switch (status) { case LogStatus.Error: { StackTrace stackTrace = new StackTrace(); string frameMethodName = ""; for (int i = 0; i < stackTrace.FrameCount; ++i) { frameMethodName += stackTrace.GetFrame(i).GetMethod().Name; if (i != stackTrace.FrameCount - 1) { frameMethodName += " --> "; } } formattedStr += "\n\tFrom " + frameMethodName; Console.ForegroundColor = ConsoleColor.Red; } break; case LogStatus.Critical: { StackTrace stackTrace = new StackTrace(); string frameMethodName = ""; for (int i = 0; i < stackTrace.FrameCount; ++i) { frameMethodName += stackTrace.GetFrame(i).GetMethod().Name; if (i != stackTrace.FrameCount - 1) { frameMethodName += " --> "; } } formattedStr += "\n\tFrom " + frameMethodName; Console.ForegroundColor = ConsoleColor.DarkRed; throw new Exception("Critical error - game cannot continue: " + formattedStr); } break; case LogStatus.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break; } OnWrite?.Invoke(null, new LogEventArgs() { loggedStr = formattedStr }); Console.WriteLine(formattedStr); Console.ForegroundColor = ConsoleColor.Gray; }
public static string GetIcon(LogStatus LogStatus) { string result; if (Icon.icon.ContainsKey(LogStatus)) { result = Icon.icon[LogStatus]; } else { string text = LogStatus.ToString().ToUpper(); switch (text) { case "FAIL": result = "times-circle-o"; return(result); case "ERROR": result = "exclamation-circle"; return(result); case "FATAL": result = "exclamation-circle"; return(result); case "PASS": result = "check-circle-o"; return(result); case "INFO": result = "info-circle"; return(result); case "WARNING": result = "warning"; return(result); case "SKIP": result = "chevron-circle-right"; return(result); } result = "question"; } return(result); }
public void Log(string str, LogStatus status = LogStatus.General) { switch (status) { case LogStatus.Error: Console.ForegroundColor = ConsoleColor.Red; break; case LogStatus.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break; case LogStatus.Success: Console.ForegroundColor = ConsoleColor.Green; break; } if (verbose) { Console.WriteLine("[" + status.ToString() + "] " + str); } Console.ForegroundColor = ConsoleColor.Gray; }
static private string CreateLogMessage(LogStatus status, string message) { return($"{DateTime.Now} [{status.ToString()}] {message} {Environment.NewLine}"); }
static private string GetFormattedLogStatusString(LogStatus status) { return($"[{status.ToString()}]"); }