private void UpdateControl(LoggingEvent loggingEvent) { // There may be performance issues if the buffer gets too long // So periodically clear the buffer if (richtextBox.TextLength > maxTextLength) { richtextBox.Clear(); richtextBox.AppendText(string.Format("(earlier messages cleared because log length exceeded maximum of {0})\n\r", maxTextLength)); } // 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 if (!selectedStyle.BackgroundColor.IsEmpty) { richtextBox.SelectionBackColor = selectedStyle.BackgroundColor; } if (!selectedStyle.ForgroundColor.IsEmpty) { richtextBox.SelectionColor = selectedStyle.ForgroundColor; } // 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)); }
/// <summary> /// Add a mapping of level to text style - done by the config file /// </summary> /// <param name="mapping">The mapping to add</param> /// <remarks> /// <para> /// Add a <see cref="LevelTextStyle"/> mapping to this appender. /// Each mapping defines the text style for a level. /// </para> /// </remarks> public void AddMapping(LevelTextStyle mapping) { _levelMapping.Add(mapping); }