TraceListenerCollection Class

Provides a thread-safe list of TraceListener objects.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public ref class TraceListenerCollection : IList, ICollection, IEnumerable
public class TraceListenerCollection implements IList, ICollection, 
public class TraceListenerCollection implements IList, ICollection, 

The TraceListenerCollection list is used to specify the output listeners for the Trace.Listeners and the Debug.Listeners collections. You cannot create an instance of this class.

This list is thread-safe, however the methods used to access the list and the enumerator do not take synchronization locks. Instead, the collection is copied, the copy is modified, and a reference is set to the copy of the collection. Methods like Add, Remove, and Clear modify the elements in the collection.

The TraceListenerCollection class provides the Count property for information about the list. It also provides the following methods: Contains, GetEnumerator, IndexOf.

This class also provides the following methods to modify the list: Add, Clear, Insert, and Remove. The CopyTo method copies a part of the list to an array. The RemoveAt method deletes the list member at a specified index number.

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

/* Create a ConsoletTraceListener and add it to the trace listeners. */
ConsoleTraceListener^ myWriter =
   gcnew ConsoleTraceListener( );
Trace::Listeners->Add( myWriter );

/* Create a ConsoleTraceListener and add it to the trace listeners. 
ConsoleTraceListener myWriter =
    new ConsoleTraceListener();

// Create a listener, which outputs to the console screen, and 
// add it to the trace listeners. 
var myWriter : TextWriterTraceListener = new TextWriterTraceListener(System.Console.Out)
Trace.Write("Error output")


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0