private static void WriteLevel(LogEvent logEvent, TextWriter builder) { var text = logEvent.Level switch { LogEventLevel.Verbose => "VRB", LogEventLevel.Debug => "DBG", LogEventLevel.Information => "INF", LogEventLevel.Warning => "WRN", LogEventLevel.Error => "ERR", LogEventLevel.Fatal => "FTL", _ => null, }; var colorCode = logEvent.Level switch { LogEventLevel.Verbose => ColorCode.LvlTokenVrb, LogEventLevel.Debug => ColorCode.LvlTokenDbg, LogEventLevel.Information => ColorCode.LvlTokenInf, LogEventLevel.Warning => ColorCode.LvlTokenWrn, LogEventLevel.Error => ColorCode.LvlTokenErr, LogEventLevel.Fatal => ColorCode.LvlTokenFtl, _ => ColorCode.LvlTokenInf, }; ColorCodeContext.Write(builder, colorCode, text); }
private static void WriteException(LogEvent logEvent, TextWriter builder) { if (logEvent.Exception == null) { return; } var lines = logEvent.Exception.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var colorCode = line.StartsWith(" ", StringComparison.InvariantCultureIgnoreCase) ? ColorCode.TimeStamp_Property_Exception : ColorCode.Message_Exception; ColorCodeContext.Write(builder, colorCode, line + Environment.NewLine); } }