public class TraceListenerCollection : IList, ICollection, IEnumerable
|
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 TraceListenerCollection.Add, TraceListenerCollection.Remove, and TraceListenerCollection.Clear modify the elements in the collection.
The TraceListenerCollection class provides the TraceListenerCollection.Count property for information about the list. It also provides the following methods: TraceListenerCollection.Contains, TraceListenerCollection.GetEnumerator, TraceListenerCollection.IndexOf.
This class also provides the following methods to modify the list: TraceListenerCollection.Add, TraceListenerCollection.Clear, TraceListenerCollection.Insert, and TraceListenerCollection.Remove. The TraceListenerCollection.CopyTo method copies a part of the list to an array. The TraceListenerCollection.RemoveAt method deletes the list member at a specified index number.
/* Create a listener, which outputs to the console screen, and * add it to the trace listeners. */ TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out); Trace.Listeners.Add(myWriter);
Count | Read-only Gets the number of listeners in the list. |
Item | Read-only Overloaded: Item[string name] {get Gets the first TraceListener in the list with the specified name. |
Item | Read-write Overloaded: Item[int i] {get Gets or sets the TraceListener at the specified index. |
Add | Adds a TraceListener to the list. |
AddRange | Overloaded:AddRange(TraceListener[] value) Adds an array of TraceListener objects to the list. |
AddRange | Overloaded:AddRange(TraceListenerCollection value) 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 (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetEnumerator | Gets an enumerator for this list. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
IndexOf | Gets the index of the specified listener. |
Insert | Inserts the listener at the specified index. |
Remove | Overloaded:Remove(string name) Removes from the collection the first TraceListener with the specified name. |
Remove | Overloaded:Remove(TraceListener listener) Removes from the collection the specified TraceListener. |
RemoveAt | Removes from the collection the TraceListener at the specified index. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public int Count {get;}
|
public TraceListener this[string name] {get;}
|
name
public TraceListener this[int i] {get; set;}
|
i
myTraceListenerColl[2]
.
public int Add( |
listener
/* Create a listener, which outputs to the console screen, and * add it to the trace listeners. */ TextWriterTraceListener myWriter = new TextWriterTraceListener(); myWriter.Writer = System.Console.Out; Trace.Listeners.Add(myWriter);
public void AddRange( |
value
public void AddRange( |
value
public void Clear(); |
public bool Contains( |
listener
public void CopyTo( |
listeners
index
~TraceListenerCollection(); |
public IEnumerator GetEnumerator(); |
public virtual int GetHashCode(); |
public Type GetType(); |
public int IndexOf( |
listener
public void Insert( |
index
listener
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The index is not a valid index in the list. |
The index is zero-based. Therefore, if you want to insert the listener into the third position, you must call
myTraceListenerColl.Insert(2, myNewListener)
.
protected object MemberwiseClone(); |
public void Remove( |
name
Exception Type | Condition |
---|---|
ArgumentException | A listener with the given name does not exist in the list. |
public void Remove( |
listener
Exception Type | Condition |
---|---|
ArgumentException | The listener does not exist in the list. |
public void RemoveAt( |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The index is not a valid index in the list. |
myTraceListenerColl.RemoveAt(2)
.
public virtual string ToString(); |