TraceListenerCollection.Add(TraceListener) Method

Definition

Adds a TraceListener to the list.

C#
public int Add(System.Diagnostics.TraceListener listener);

Parameters

listener
TraceListener

A TraceListener to add to the list.

Returns

The position at which the new listener was inserted.

Examples

The following example creates a TextWriterTraceListener that outputs to the console screen. The code then adds the new listener to the Trace.Listeners.

C#
/* Create a listener, which outputs to the console screen, and
  * add it to the trace listeners. */
TextWriterTraceListener myWriter = new TextWriterTraceListener();
myWriter.Writer = System.Console.Out;
Trace.Listeners.Add(myWriter);

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also