Formatting log events to ConsoleTraceListener

Topics: Logging Application Block
May 16, 2007 at 6:44 PM
I'm just getting my feet wet with the Logging Application Block. I've experimented with a variety of Trace Listeners (database, rolling file, etc) but currently have a need to simply write to the Console. So I added a new System.Diagnostics TraceListener. I selected System.Diagnostics.ConsoleTraceListener for the type. The problem I'm encountering is that I do not know how to control the format of the entries written to the Console. Unlike the other listeners, it is apparently not possible to set a Formatter for a System.Diagnostics listener.

Thanks in advance for any assistance.
May 17, 2007 at 3:35 PM
One of the values of the Enterprise Library TraceListeners is that they help with formatting. Your normal .NET Framework TraceListeneres do not.

You could create a custom console trace listener that uses a formatter just like the Enterprise Library TraceListeners. Someone may know of an easier solution.




David Hayden
Microsoft MVP C#
May 17, 2007 at 9:50 PM
Thanks Dave.

I used DebugTraceListener from the QuickStart samples as a template and built a ConsoleTraceListener in a matter of minutes. I then created an additional TextFormatter in my config file that just dumps the message. It works as expected.