TraceListenerCollection Class
Provides a thread-safe list of TraceListener objects.
Namespace: System.Diagnostics
Assembly: System (in System.dll)
The TraceListenerCollection type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Count | Gets the number of listeners in the list. |
![]() ![]() | Item[Int32] | Gets or sets the TraceListener at the specified index. |
![]() ![]() | Item[String] | Gets the first TraceListener in the list with the specified name. |
| Name | Description | |
|---|---|---|
![]() ![]() | Add | Adds a TraceListener to the list. |
![]() | AddRange(TraceListener[]) | Adds an array of TraceListener objects to the list. |
![]() | AddRange(TraceListenerCollection) | Adds the contents of another TraceListenerCollection to the list. |
![]() ![]() | Clear | Clears all the listeners from the list. |
![]() ![]() | Contains | Checks whether the list contains the specified listener. |
![]() ![]() | CopyTo | Copies a section of the current TraceListenerCollection list to the specified array at the specified index. |
![]() ![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetEnumerator | Gets an enumerator for this list. |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | IndexOf | Gets the index of the specified listener. |
![]() ![]() | Insert | Inserts the listener at the specified index. |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | Remove(String) | Removes from the collection the first TraceListener with the specified name. |
![]() ![]() | Remove(TraceListener) | Removes from the collection the specified TraceListener. |
![]() ![]() | RemoveAt | Removes from the collection the TraceListener at the specified index. |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | AsParallel | Enables parallelization of a query. (Defined by ParallelEnumerable.) |
![]() | AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) |
![]() ![]() | Cast<TResult> | Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) |
![]() ![]() | OfType<TResult> | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | ICollection.CopyTo | Infrastructure. Copies a section of the current TraceListenerCollection to the specified array of TraceListener objects. |
![]() ![]() ![]() | ICollection.IsSynchronized | Infrastructure. Gets a value indicating whether access to the TraceListenerCollection is synchronized (thread safe). |
![]() ![]() ![]() | ICollection.SyncRoot | Infrastructure. Gets an object that can be used to synchronize access to the TraceListenerCollection. |
![]() ![]() ![]() | IList.Add | Infrastructure. Adds a trace listener to the TraceListenerCollection. |
![]() ![]() ![]() | IList.Contains | Infrastructure. Determines whether the TraceListenerCollection contains a specific object. |
![]() ![]() ![]() | IList.IndexOf | Infrastructure. Determines the index of a specific object in the TraceListenerCollection. |
![]() ![]() ![]() | IList.Insert | Infrastructure. Inserts a TraceListener object at the specified position in the TraceListenerCollection. |
![]() ![]() ![]() | IList.IsFixedSize | Infrastructure. Gets a value indicating whether the TraceListenerCollection has a fixed size. |
![]() ![]() ![]() | IList.IsReadOnly | Infrastructure. Gets a value indicating whether the TraceListenerCollection is read-only |
![]() ![]() ![]() | IList.Item | Infrastructure. Gets or sets the TraceListener at the specified index in the TraceListenerCollection. |
![]() ![]() ![]() | IList.Remove | Infrastructure. Removes an object from the TraceListenerCollection. |
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.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.







