Change ConsoleTraceListener output

Topics: Logging Application Block
Aug 6, 2007 at 6:42 PM
How do I change the trace output when I am using a System.Diagnostics TraceListener (more specifically ConsoleTraceListener)? I tried changing the TraceOutputOptions property, but that does not seem to affect the ouput. Is there anyway to associate a TextFormatter with the trace listener?
Aug 6, 2007 at 7:46 PM
User Console.SetOut to changer where the output of the Console is going.
Aug 6, 2007 at 8:23 PM
I want the change the format of the trace output, and not where my trace output is going (Console.SetOut). I am sorry if my original question was not clear.
Aug 7, 2007 at 12:25 AM

The way to configure the output for the console trace listener is through the TraceOutputOptions, but this will only affect which "Extended Properties" will be shown; you should see the additional information at the end of an entry.
You cannot attach a text formatter to it, as this is a .NET trace listener.

Aug 8, 2007 at 4:53 PM
Thank you fsimonazzi
Aug 12, 2010 at 7:42 AM

Hopefully this will help anyone who has this issue in future (EntLib 5.0 compatible). The only way I could do it was write a custom trace listener (it's really simple)

    public class FormattableConsoleTraceListener : CustomTraceListener
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
            if (data is LogEntry && this.Formatter != null)
                this.WriteLine(this.Formatter.Format(data as LogEntry));

        public override void Write(string message)

        public override void WriteLine(string message)
            Console.WriteLine (message);