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:
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"));
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |