private void Output(LogEventInfo logEvent, string message) { IntPtr hConsole = ConsoleWin32Api.GetStdHandle(ErrorStream ? ConsoleWin32Api.STD_ERROR_HANDLE : ConsoleWin32Api.STD_OUTPUT_HANDLE); ConsoleWin32Api.CONSOLE_SCREEN_BUFFER_INFO csbi; ConsoleWin32Api.GetConsoleScreenBufferInfo(hConsole, out csbi); ConsoleRowHighlightingRule matchingRule = null; foreach (ConsoleRowHighlightingRule cr in RowHighlightingRules) { if (cr.CheckCondition(logEvent)) { matchingRule = cr; break; } } if (UseDefaultRowHighlightingRules && matchingRule == null) { foreach (ConsoleRowHighlightingRule cr in _defaultConsoleRowHighlightingRules) { if (cr.CheckCondition(logEvent)) { matchingRule = cr; break; } } } if (matchingRule == null) { matchingRule = ConsoleRowHighlightingRule.Default; } ushort newColor = ColorFromForegroundAndBackground(csbi.wAttributes, matchingRule.ForegroundColor, matchingRule.BackgroundColor); message = message.Replace("\a", "\a\a"); foreach (ConsoleWordHighlightingRule hl in WordHighlightingRules) { message = hl.ReplaceWithEscapeSequences(message); } if (ErrorStream) { ColorizeEscapeSequences(Console.Error, hConsole, message, newColor, csbi.wAttributes); } else { ColorizeEscapeSequences(Console.Out, hConsole, message, newColor, csbi.wAttributes); } ConsoleWin32Api.CONSOLE_SCREEN_BUFFER_INFO csbi2; ConsoleWin32Api.GetConsoleScreenBufferInfo(hConsole, out csbi2); ConsoleWin32Api.SetConsoleTextAttribute(hConsole, csbi.wAttributes); int xsize = csbi2.dwSize.x; int xpos = csbi2.dwCursorPosition.x; uint written = 0; ConsoleWin32Api.FillConsoleOutputAttribute(hConsole, newColor, xsize - xpos, csbi2.dwCursorPosition, out written); ConsoleWin32Api.SetConsoleTextAttribute(hConsole, csbi.wAttributes); if (ErrorStream) { Console.Error.WriteLine(); } else { Console.WriteLine(); } }
/// <summary> /// Removes the first occurrence of a specific ConsoleRowHighlightingRule from this ConsoleRowHighlightingRuleCollection. /// </summary> /// <param name="value"> /// The ConsoleRowHighlightingRule value to remove from this ConsoleRowHighlightingRuleCollection. /// </param> public virtual void Remove(ConsoleRowHighlightingRule value) { this.List.Remove(value); }
/// <summary> /// Inserts an element into the ConsoleRowHighlightingRuleCollection at the specified index /// </summary> /// <param name="index"> /// The index at which the ConsoleRowHighlightingRule is to be inserted. /// </param> /// <param name="value"> /// The ConsoleRowHighlightingRule to insert. /// </param> public virtual void Insert(int index, ConsoleRowHighlightingRule value) { this.List.Insert(index, value); }
/// <summary> /// Return the zero-based index of the first occurrence of a specific value /// in this ConsoleRowHighlightingRuleCollection /// </summary> /// <param name="value"> /// The ConsoleRowHighlightingRule value to locate in the ConsoleRowHighlightingRuleCollection. /// </param> /// <returns> /// The zero-based index of the first occurrence of the _ELEMENT value if found; /// -1 otherwise. /// </returns> public virtual int IndexOf(ConsoleRowHighlightingRule value) { return(this.List.IndexOf(value)); }
/// <summary> /// Determines whether a specfic ConsoleRowHighlightingRule value is in this ConsoleRowHighlightingRuleCollection. /// </summary> /// <param name="value"> /// The ConsoleRowHighlightingRule value to locate in this ConsoleRowHighlightingRuleCollection. /// </param> /// <returns> /// true if value is found in this ConsoleRowHighlightingRuleCollection; /// false otherwise. /// </returns> public virtual bool Contains(ConsoleRowHighlightingRule value) { return(this.List.Contains(value)); }
/// <summary> /// Adds an instance of type ConsoleRowHighlightingRule to the end of this ConsoleRowHighlightingRuleCollection. /// </summary> /// <param name="value"> /// The ConsoleRowHighlightingRule to be added to the end of this ConsoleRowHighlightingRuleCollection. /// </param> public virtual void Add(ConsoleRowHighlightingRule value) { this.List.Add(value); }