/// <summary> /// Initializes static members of the ConsoleRowHighlightingRule class. /// </summary> static ConsoleRowHighlightingRule() { Default = new ConsoleRowHighlightingRule(null, ConsoleOutputColor.NoChange, ConsoleOutputColor.NoChange); }
private void Output(LogEventInfo logEvent, string message) { var oldForegroundColor = Console.ForegroundColor; var oldBackgroundColor = Console.BackgroundColor; try { ConsoleRowHighlightingRule matchingRule = null; foreach (var cr in RowHighlightingRules) { if (cr.CheckCondition(logEvent)) { matchingRule = cr; break; } } if (UseDefaultRowHighlightingRules && matchingRule == null) { foreach (var cr in defaultConsoleRowHighlightingRules) { if (cr.CheckCondition(logEvent)) { matchingRule = cr; break; } } } if (matchingRule == null) { matchingRule = ConsoleRowHighlightingRule.Default; } if (matchingRule.ForegroundColor != ConsoleOutputColor.NoChange) { Console.ForegroundColor = (ConsoleColor)matchingRule.ForegroundColor; } if (matchingRule.BackgroundColor != ConsoleOutputColor.NoChange) { Console.BackgroundColor = (ConsoleColor)matchingRule.BackgroundColor; } message = message.Replace("\a", "\a\a"); foreach (var hl in WordHighlightingRules) { message = hl.ReplaceWithEscapeSequences(message); } ColorizeEscapeSequences(ErrorStream ? Console.Error : Console.Out, message, new ColorPair(Console.ForegroundColor, Console.BackgroundColor), new ColorPair(oldForegroundColor, oldBackgroundColor)); } finally { Console.ForegroundColor = oldForegroundColor; Console.BackgroundColor = oldBackgroundColor; } if (ErrorStream) { Console.Error.WriteLine(); } else { Console.WriteLine(); } }