Export (0) Print
Expand All

<listeners> Element

Specifies a listener that collects, stores, and routes messages. Listeners direct the tracing output to an appropriate target.



Child Elements

Element Description
<add> Adds a listener to the Listeners collection.
<remove> Removes a listener from the Listeners collection.


The Debug and Trace classes share the same Listeners collection. If you add a listener object to the collection in one of these classes, the other class uses the same listener. The listener classes shipped with the .NET Framework SDK derive from the TraceListener class.


The following example shows how to use the <listeners> element to add the listeners MyListener and MyEventListener to the Listeners collection. MyListener creates a file called MyListener.log and writes the output to the file. MyEventListener creates an entry in the event log.

      <trace autoflush="true" indentsize="0">
            <add name="MyListener"
                 type="System.Diagnostics.TextWriterTraceListener, Version, Culture, PublicKeyToken" 
            <add name="MyEventListener"
                 type="System.Diagnostics.EventLogTraceListener, Version, Culture, PublicKeyToken" 

Configuration File

This element can be used in the machine configuration file (Machine.config) and the application configuration file.

See Also

Trace and Debug Settings Schema | TraceListener Class | DefaultTraceListener Class | TextWriterTraceListener Class | EventLogTraceListener Class

© 2015 Microsoft