Ukadc.Diagnostics.Listeners.CustomTraceListener

Description

The CustomTraceListener is an abstract class that is used as the base for all the TraceListeners provided by the UKAdc.Diagnostics library. It aims to make creating your own TraceListener easier by removing the need to overload so many methods and applying all the necessary logic to have your trace listener work with filters etc.

Example

This is a very simple example of how the CustomTraceListener can be used as a base for a ConsoleTraceListener:

public class TestTraceListener : CustomTraceListener
{
    protected override void TraceEventCore(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
    {
        Console.WriteLine(message);
    }

    protected override void TraceEventCore(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data)
    {
        Console.WriteLine(StringFormatter.FormatData(data));
    }
}


The base CustomTraceListener takes care of much of the otherwise complex and error prone logic such as implementing Filters.

Last edited Apr 8, 2008 at 7:49 AM by joshtwist, version 13

Comments

No comments yet.