<listeners> Element for <trace>

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



  <remove ... />  

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.



Child Elements

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

Parent Elements

Element Description
configuration The root element in every configuration file used by the common language runtime and .NET Framework applications.
system.diagnostics Specifies the root element for the ASP.NET configuration section.
trace Contains listeners that collect, store, and route tracing messages.


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 derive from the TraceListener class.

Configuration File

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


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"   
            system, version=1.0.3300.0, Culture=neutral,   
          initializeData="c:\myListener.log" />  
        <add name="MyEventListener"  
            system, version=1.0.3300.0, Culture=neutral,   

See also