Listeners Collection

for RuBoard

Both the Debug and Trace classes have a static Listeners collection. This collection of TraceListeners represents a list of TraceListener objects that want to receive the output from the Debug or Trace class. Listeners are added to or removed from the collection just as with any other .NET collection.

 TextWriterTraceListener ConsoleOutput = new                        TextWriterTraceListener(Console.Out,                        "Console.Out Listener");  Trace.Listeners.Add(ConsoleOutput);  Stream OutputFile = File.Create("output.txt");  TextWriterTraceListener OutputFileListener = new                         TextWriterTraceListener(OutputFile,                                    "Output File Listener");  Trace.Listeners.Add(OutputFileListener);  Trace.Listeners.Remove("Default"); 

In this code extract, the OutputFileListener in the example will send the Trace output to a file called output.txt . The DefaultTraceListener is added automatically to the Listener collections. Any of the listeners, including the default listener, can be removed from the collection by invoking the collection's Remove method. To list all listeners in the collection:

 foreach(TraceListener tr in Trace.Listeners)  {     Console.WriteLine("\t" + tr.Name);  } 
for RuBoard


Application Development Using C# and .NET
Application Development Using C# and .NET
ISBN: 013093383X
EAN: 2147483647
Year: 2001
Pages: 158

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net