It looks like there are two methods for setting up trace listeners, Method 1 is:
Declare an instance of TraceSource class
Name the TraceSource
Call the respective methods.
Example:
TextWriterTraceListener txtTracer = new TextWriterTraceListener(@"c:\newtxtlistener.txt");
TraceSource DemoTrace = new TraceSource("DemoApp");
DemoTrace.Listeners.Add(txtTracer);
DemoTrace.Switch =
new SourceSwitch("DemoApp.Switch", "Information");
DemoTrace.TraceInformation(
"Before writing to Console");
Console.WriteLine("Writing to the Console");
DemoTrace.TraceInformation(
"After writing to Console");
Or use Listener Objects
Example:
Trace
.Listeners.Clear();
Trace.AutoFlush = true;
Trace.Listeners.Add(new TextWriterTraceListener(@"c:\newtxtlistener.txt"));
Trace.WriteLine("This is a test");
Does anyone know when to use one or the other, or is it just preference?
Thanks