Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TraceListenerCollection Class

Provides a thread-safe list of TraceListener objects.

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

public class TraceListenerCollection : IList, ICollection, IEnumerable
public class TraceListenerCollection implements IList, ICollection, 
	IEnumerable
public class TraceListenerCollection implements IList, ICollection, 
	IEnumerable
Not applicable.

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 ConsoleTraceListener and add it to the trace listeners. */
ConsoleTraceListener myWriter = new
   ConsoleTraceListener();
Trace.Listeners.Add(myWriter);


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

// Create a ConsoletTraceListener and add it to the trace listeners.
@if(@TRACE)
var myWriter : ConsoleTraceListener = new ConsoleTraceListener()
Trace.Listeners.Add(myWriter)
@end

System.Object
  System.Diagnostics.TraceListenerCollection
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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft. All rights reserved.