Language Basics C# Book

Both Debug and Trace classes maintain a list of trace listeners.
The Debug and Trace inform the listeners in case of callings to Write, Fail and Trace methods.
There are predefined trace listeners:
DefaultTraceListener
EventLogTraceListener
EventProviderTraceListener
TextWriterTraceListener
WebPageTraceListener
The following code shows how to use the trace listener to record the debug message.
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
// Clear the default listener:
Trace.Listeners.Clear();
Trace.Listeners.Add(new TextWriterTraceListener("trace.txt"));
System.IO.TextWriter tw = Console.Out;
Trace.Listeners.Add(new TextWriterTraceListener(tw));
EventLog.CreateEventSource("DemoApp", "Application");
Trace.Listeners.Add(new EventLogTraceListener("DemoApp"));
}
}