Provides a thread-safe list of TraceListener objects.
Public Class TraceListenerCollection _ Implements IList, ICollection, IEnumerable
Dim instance As TraceListenerCollection
public class TraceListenerCollection : IList, ICollection, IEnumerable
public ref class TraceListenerCollection : IList, ICollection, IEnumerable
public class TraceListenerCollection implements IList, ICollection, IEnumerable
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. Dim myWriter As New ConsoleTraceListener() Trace.Listeners.Add(myWriter)
/* Create a ConsoleTraceListener and add it to the trace listeners. */ ConsoleTraceListener myWriter = new ConsoleTraceListener(); Trace.Listeners.Add(myWriter);
// Create a ConsoletTraceListener and add it to the trace listeners. #if defined(TRACE) ConsoleTraceListener^ myWriter = gcnew ConsoleTraceListener( ); Trace::Listeners->Add( myWriter ); #endif
// Create a ConsoletTraceListener and add it to the trace listeners. @if(@TRACE) var myWriter : ConsoleTraceListener = new ConsoleTraceListener() Trace.Listeners.Add(myWriter) @end
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune