private void UpdateControl(LoggingEvent a_logging_event) { LevelTextStyle selectedStyle = m_level_mapping.Lookup(a_logging_event.Level) as LevelTextStyle; if (selectedStyle != null) { m_rich_text_box.SelectionBackColor = selectedStyle.BackColor; m_rich_text_box.SelectionColor = selectedStyle.TextColor; m_rich_text_box.SelectionFont = new Font(m_rich_text_box.Font, selectedStyle.FontStyle); } m_rich_text_box.AppendText(RenderLoggingEvent(a_logging_event)); // Clear if too big. if (MaxLines > 0) { if (m_rich_text_box.Lines.Length > MaxLines) { int pos = m_rich_text_box.GetFirstCharIndexFromLine(1); m_rich_text_box.Select(0, pos); m_rich_text_box.SelectedText = String.Empty; } } // Autoscroll. m_rich_text_box.Select(m_rich_text_box.TextLength, 0); m_rich_text_box.ScrollToCaret(); }
/// <summary> /// Translates a log4net level to a syslog severity. /// </summary> /// <param name="level">A log4net level.</param> /// <returns>A syslog severity.</returns> /// <remarks> /// <para> /// Translates a log4net level to a syslog severity. /// </para> /// </remarks> protected virtual SyslogSeverity GetSeverity(Level level) { LevelSeverity levelSeverity = m_levelMapping.Lookup(level) as LevelSeverity; if (levelSeverity != null) { return(levelSeverity.Severity); } if (level >= Level.Alert) { return(SyslogSeverity.Alert); } if (level >= Level.Critical) { return(SyslogSeverity.Critical); } if (level >= Level.Error) { return(SyslogSeverity.Error); } if (level >= Level.Warn) { return(SyslogSeverity.Warning); } if (level >= Level.Notice) { return(SyslogSeverity.Notice); } if (level >= Level.Info) { return(SyslogSeverity.Informational); } return(SyslogSeverity.Debug); }
private void UpdateControl(LoggingEvent loggingEvent) { if (!richTextBox.Visible) { return; } // There may be performance issues if the buffer gets too long // So periodically clear the buffer if (richTextBox.TextLength > maxTextLength) { //richTextBox.Clear(); //richTextBox.SuspendLayout(); while (richTextBox.TextLength > (int)(maxTextLength * 0.9)) { richTextBox.Select(0, richTextBox.GetFirstCharIndexFromLine(1)); // select the first line richTextBox.SelectedText = ""; } //richTextBox.AppendText(string.Format("(Cleared log length max: {0})\n", maxTextLength)); //richTextBox.ScrollToCaret(); //richTextBox.ResumeLayout(); } // look for a style mapping LevelTextStyle selectedStyle = levelMapping.Lookup(loggingEvent.Level) as LevelTextStyle; if (selectedStyle != null) { // set the colors of the text about to be appended richTextBox.SelectionBackColor = selectedStyle.BackColor; richTextBox.SelectionColor = selectedStyle.TextColor; // alter selection font as much as necessary // missing settings are replaced by the font settings on the control if (selectedStyle.Font != null) { // set Font Family, size and styles richTextBox.SelectionFont = selectedStyle.Font; } else if (selectedStyle.PointSize > 0 && richTextBox.Font.SizeInPoints != selectedStyle.PointSize) { // use control's font family, set size and styles float size = selectedStyle.PointSize > 0.0f ? selectedStyle.PointSize : richTextBox.Font.SizeInPoints; richTextBox.SelectionFont = new Font(richTextBox.Font.FontFamily.Name, size, selectedStyle.FontStyle); } else if (richTextBox.Font.Style != selectedStyle.FontStyle) { // use control's font family and size, set styles richTextBox.SelectionFont = new Font(richTextBox.Font, selectedStyle.FontStyle); } } richTextBox.AppendText(RenderLoggingEvent(loggingEvent)); richTextBox.ScrollToCaret(); }
private void UpdateText(LoggingEvent loggingEvent) { if (levelMapping.Lookup(loggingEvent.Level) is ColoredConsoleAppender.LevelColors selectedStyle) { RichTextBox.Select(RichTextBox.TextLength, 0); RichTextBox.SelectionColor = selectedStyle.ForeColor.ToColor(); } RichTextBox.AppendText(RenderLoggingEvent(loggingEvent)); //if (RichTextBox.TextLength > 0) RichTextBox?.AppendText(Environment.NewLine); //RichTextBox.AppendText(text); RichTextBox.ScrollToCaret(); }
/// <summary> /// Add logging event to configured control /// </summary> /// <param name="loggingEvent">The event to log</param> private void UpdateControl(LoggingEvent loggingEvent) { // There may be performance issues if the buffer gets too long // So periodically clear the buffer if (_richtextBox.TextLength > _maxBufferLength) { _richtextBox.Clear(); _richtextBox.AppendText( string.Format("(earlier messages cleared because log length exceeded maximum of {0})\n\n", _maxBufferLength)); } // look for a style mapping var selectedStyle = _levelMapping.Lookup(loggingEvent.Level) as LevelTextStyle; if (selectedStyle != null) { // set the colors of the text about to be appended _richtextBox.SelectionBackColor = selectedStyle.BackColor; _richtextBox.SelectionColor = selectedStyle.TextColor; // alter selection font as much as necessary // missing settings are replaced by the font settings on the control if (selectedStyle.Font != null) { // set Font Family, size and styles _richtextBox.SelectionFont = selectedStyle.Font; } else if (selectedStyle.PointSize > 0 && _richtextBox.Font.SizeInPoints != selectedStyle.PointSize) { // use control's font family, set size and styles var size = selectedStyle.PointSize > 0.0f ? selectedStyle.PointSize : _richtextBox.Font.SizeInPoints; _richtextBox.SelectionFont = new Font(_richtextBox.Font.FontFamily.Name, size, selectedStyle.FontStyle); } else if (_richtextBox.Font.Style != selectedStyle.FontStyle) { // use control's font family and size, set styles _richtextBox.SelectionFont = new Font(_richtextBox.Font, selectedStyle.FontStyle); } } _richtextBox.AppendText(RenderLoggingEvent(loggingEvent)); }
/// <summary> /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)" /> method. /// </summary> /// <param name="loggingEvent">The event to log.</param> /// <remarks> /// <para> /// Writes the event to the console. /// </para> /// <para> /// The format of the output will depend on the appender's layout. /// </para> /// </remarks> protected override void Append(LoggingEvent loggingEvent) { string text = RenderLoggingEvent(loggingEvent); LevelColors levelColors = m_levelMapping.Lookup(loggingEvent.Level) as LevelColors; if (levelColors != null) { text = levelColors.CombinedColor + text; } text = ((text.Length > 1) ? ((!text.EndsWith("\r\n") && !text.EndsWith("\n\r")) ? ((!text.EndsWith("\n") && !text.EndsWith("\r")) ? (text + "\u001b[0m") : text.Insert(text.Length - 1, "\u001b[0m")) : text.Insert(text.Length - 2, "\u001b[0m")) : ((text[0] != '\n' && text[0] != '\r') ? (text + "\u001b[0m") : ("\u001b[0m" + text))); if (m_writeToErrorStream) { Console.Error.Write(text); } else { Console.Write(text); } }
/// <summary> /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)" /> method. /// </summary> /// <param name="loggingEvent">The event to log.</param> /// <remarks> /// <para> /// Writes the event to the console. /// </para> /// <para> /// The format of the output will depend on the appender's layout. /// </para> /// </remarks> protected override void Append(LoggingEvent loggingEvent) { TextWriter textWriter = (!m_writeToErrorStream) ? Console.Out : Console.Error; Console.ResetColor(); LevelColors levelColors = m_levelMapping.Lookup(loggingEvent.Level) as LevelColors; if (levelColors != null) { if (levelColors.HasBackColor) { Console.BackgroundColor = levelColors.BackColor; } if (levelColors.HasForeColor) { Console.ForegroundColor = levelColors.ForeColor; } } string value = RenderLoggingEvent(loggingEvent); textWriter.Write(value); Console.ResetColor(); }