/// <summary>
 /// Initializes static members of the ConsoleRowHighlightingRule class.
 /// </summary>
 static ConsoleRowHighlightingRule()
 {
     Default = new ConsoleRowHighlightingRule(null, ConsoleOutputColor.NoChange, ConsoleOutputColor.NoChange);
 }
Пример #2
0
 /// <summary>
 /// Initializes static members of the ConsoleRowHighlightingRule class.
 /// </summary>
 static ConsoleRowHighlightingRule()
 {
     Default = new ConsoleRowHighlightingRule(null, ConsoleOutputColor.NoChange, ConsoleOutputColor.NoChange);
 }
Пример #3
0
        private void Output(LogEventInfo logEvent, string message)
        {
            ConsoleColor oldForegroundColor = Console.ForegroundColor;
            ConsoleColor oldBackgroundColor = Console.BackgroundColor;

            try
            {
                ConsoleRowHighlightingRule matchingRule = null;

                foreach (ConsoleRowHighlightingRule cr in this.RowHighlightingRules)
                {
                    if (cr.CheckCondition(logEvent))
                    {
                        matchingRule = cr;
                        break;
                    }
                }

                if (this.UseDefaultRowHighlightingRules && matchingRule == null)
                {
                    foreach (ConsoleRowHighlightingRule 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 (ConsoleWordHighlightingRule hl in this.WordHighlightingRules)
                {
                    message = hl.ReplaceWithEscapeSequences(message);
                }

                ColorizeEscapeSequences(this.ErrorStream ? Console.Error : Console.Out, message, new ColorPair(Console.ForegroundColor, Console.BackgroundColor), new ColorPair(oldForegroundColor, oldBackgroundColor));
            }
            finally
            {
                Console.ForegroundColor = oldForegroundColor;
                Console.BackgroundColor = oldBackgroundColor;
            }

            if (this.ErrorStream)
            {
                Console.Error.WriteLine();
            }
            else
            {
                Console.WriteLine();
            }
        }