A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/trace-listeners below:

Trace Listeners - .NET Framework

Note

This article is specific to .NET Framework. It doesn't apply to newer implementations of .NET, including .NET 6 and later versions.

When using Trace, Debug and TraceSource, you must have a mechanism for collecting and recording the messages that are sent. Trace messages are received by listeners. The purpose of a listener is to collect, store, and route tracing messages. Listeners direct the tracing output to an appropriate target, such as a log, window, or text file.

Listeners are available to the Debug, Trace, and TraceSource classes, each of which can send its output to a variety of listener objects. The following are the commonly used predefined listeners:

If you want any listener besides the DefaultTraceListener to receive Debug, Trace and TraceSource output, you must add it to the Listeners collection. For more information, see How to: Create and Initialize Trace Listeners and How to: Use TraceSource and Filters with Trace Listeners. Any listener in the Listeners collection gets the same messages from the trace output methods. For example, suppose you set up two listeners: a TextWriterTraceListener and an EventLogTraceListener. Each listener receives the same message. The TextWriterTraceListener would direct its output to a stream, and the EventLogTraceListener would direct its output to an event log.

The following example shows how to send output to the Listeners collection.

' Use this example when debugging.
Debug.WriteLine("Error in Widget 42")
' Use this example when tracing.
Trace.WriteLine("Error in Widget 42")
// Use this example when debugging.
System.Diagnostics.Debug.WriteLine("Error in Widget 42");
// Use this example when tracing.
System.Diagnostics.Trace.WriteLine("Error in Widget 42");

Debug and trace share the same Listeners collection, so if you add a listener object to a Debug.Listeners collection in your application, it gets added to the Trace.Listeners collection as well.

The following example shows how to use a listener to send tracing information to a console:

Trace.Listeners.Clear()
Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))
System.Diagnostics.Trace.Listeners.Clear();
System.Diagnostics.Trace.Listeners.Add(
   new System.Diagnostics.TextWriterTraceListener(Console.Out));
Developer-Defined Listeners

You can define your own listeners by inheriting from the TraceListener base class and overriding its methods with your customized methods. For more information on creating developer-defined listeners, see TraceListener in the .NET Framework reference.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4