This is in followup to my question: Flexible Logging Interface...
I now want to write a custom log4net appender for a multiline TextBox, for my WinForms 2.0 applicat
Above sample by Klodoma is quite good. If you change the textbox to a richtextbox, you can do more with the output. Here is some code to color code messages by level:
System.Drawing.Color text_color;
switch (loggingEvent.Level.DisplayName.ToUpper())
{
case "FATAL":
text_color = System.Drawing.Color.DarkRed;
break;
case "ERROR":
text_color = System.Drawing.Color.Red;
break;
case "WARN":
text_color = System.Drawing.Color.DarkOrange;
break;
case "INFO":
text_color = System.Drawing.Color.Teal;
break;
case "DEBUG":
text_color = System.Drawing.Color.Green;
break;
default:
text_color = System.Drawing.Color.Black;
break;
}
_TextBox.BeginInvoke((MethodInvoker)delegate
{
_TextBox.SelectionColor = text_color;
_TextBox.AppendText(RenderLoggingEvent(loggingEvent));
});
If you really want to, the colors could be mapped from the log4net config in the same fashion as the ColorConsoleAppender, but I leave that for the next coder to stumble onto this sample...