Επεξεργασία

Κοινή χρήση μέσω


TraceListenerCollection Class

Definition

Provides a thread-safe list of TraceListener objects.

public ref class TraceListenerCollection : System::Collections::IList
public class TraceListenerCollection : System.Collections.IList
type TraceListenerCollection = class
    interface ICollection
    interface IEnumerable
    interface IList
type TraceListenerCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class TraceListenerCollection
Implements IList
Inheritance
TraceListenerCollection
Implements

Examples

The following example creates a ConsoleTraceListener 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.
#if defined(TRACE)
ConsoleTraceListener^ myWriter = gcnew ConsoleTraceListener( );
Trace::Listeners->Add( myWriter );
#endif
/* Create a ConsoleTraceListener and add it to the trace listeners. */
var myWriter = new ConsoleTraceListener();
Trace.Listeners.Add(myWriter);
' Create a ConsoleTraceListener and add it to the trace listeners. 
Dim myWriter As New ConsoleTraceListener()
Trace.Listeners.Add(myWriter)

Remarks

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.

Properties

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.

Methods

Add(TraceListener)

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(TraceListener)

Checks whether the list contains the specified listener.

CopyTo(TraceListener[], Int32)

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)
GetEnumerator()

Gets an enumerator for this list.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(TraceListener)

Gets the index of the specified listener.

Insert(Int32, TraceListener)

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(Int32)

Removes from the collection the TraceListener at the specified index.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies a section of the current TraceListenerCollection to the specified array of TraceListener objects.

ICollection.IsSynchronized

Gets a value indicating whether access to the TraceListenerCollection is synchronized (thread safe).

ICollection.SyncRoot

Gets an object that can be used to synchronize access to the TraceListenerCollection.

IList.Add(Object)

Adds a trace listener to the TraceListenerCollection.

IList.Contains(Object)

Determines whether the TraceListenerCollection contains a specific object.

IList.IndexOf(Object)

Determines the index of a specific object in the TraceListenerCollection.

IList.Insert(Int32, Object)

Inserts a TraceListener object at the specified position in the TraceListenerCollection.

IList.IsFixedSize

Gets a value indicating whether the TraceListenerCollection has a fixed size.

IList.IsReadOnly

Gets a value indicating whether the TraceListenerCollection is read-only.

IList.Item[Int32]

Gets or sets the TraceListener at the specified index in the TraceListenerCollection.

IList.Remove(Object)

Removes an object from the TraceListenerCollection.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also