/// <summary> /// Prints the LogEvent using the StandardOutWriter. /// </summary> /// <param name="logEvent"></param> public static void PrintLogEvent(LogEvent logEvent) { ConsoleColor?color = null; if (UseColors) { var logLevel = logEvent.LogLevel(); switch (logLevel) { case LogLevel.DebugLevel: color = DebugColor; break; case LogLevel.InfoLevel: color = InfoColor; break; case LogLevel.WarningLevel: color = WarningColor; break; case LogLevel.ErrorLevel: color = ErrorColor; break; } } StandardOutWriter.WriteLine(logEvent.ToString(), color); }
public static void PrintLogEvent(LogEvent logEvent) { ConsoleColor? color = null; if(UseColors) { var logLevel = logEvent.LogLevel(); switch(logLevel) { case LogLevel.DebugLevel: color = DebugColor; break; case LogLevel.InfoLevel: color = InfoColor; break; case LogLevel.WarningLevel: color = WarningColor; break; case LogLevel.ErrorLevel: color = ErrorColor; break; } } StandardOutWriter.WriteLine(logEvent.ToString(), color); }
/// <summary> /// Prints a specified event to the console. /// </summary> /// <param name="logEvent">The event to print</param> public static void PrintLogEvent(LogEvent logEvent) { try { ConsoleColor?color = null; if (UseColors) { var logLevel = logEvent.LogLevel(); switch (logLevel) { case LogLevel.DebugLevel: color = DebugColor; break; case LogLevel.InfoLevel: color = InfoColor; break; case LogLevel.WarningLevel: color = WarningColor; break; case LogLevel.ErrorLevel: color = ErrorColor; break; } } StandardOutWriter.WriteLine(logEvent.ToString(), color); } catch (FormatException) { /* * If we've reached this point, the `logEvent` itself is informatted incorrectly. * Therefore we have to treat the data inside the `logEvent` as suspicious and avoid throwing * a second FormatException. */ var sb = new StringBuilder(); sb.AppendFormat("[ERROR][{0}][Thread {1}][StandardOutLogger] ", logEvent.Timestamp, 0); sb.AppendFormat("Encoutered System.FormatException while recording log: [" + logEvent.LogLevel().PrettyNameFor() + "]") .AppendFormat("[" + logEvent.LogSource + "][" + logEvent.Message + "]"); string msg; switch (logEvent.Message) { case LogMessage formatted: // a parameterized log msg = "str=[" + formatted.Format + "],args=[" + string.Join(",", formatted.Args) + "]"; break; case string unformatted: // pre-formatted or non-parameterized log msg = unformatted; break; default: // surprise! msg = logEvent.Message.ToString(); break; } sb.Append(msg) .Append("Please take a look at the logging call where this occurred and fix your format string."); StandardOutWriter.WriteLine(sb.ToString(), ErrorColor); } }