<listeners> Element for <source>

Adds or removes listeners in the Listeners collection for a TraceSource. A listener directs the tracing output to an appropriate target, such as a log, window, or text file.

<configuration>
<system.diagnostics>
<sources>
<source>
<listeners> Element

Syntax

<listeners>   
  <add>...</add>  
  <remove ... />  
  <clear/>  
</listeners>  

Attributes and Elements

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

Attributes

None.

Child Elements

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

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 trace listeners that collect, store, and route messages and the level where a trace switch is set.
sources Contains trace sources that initiate tracing messages.
source Specifies a trace source that initiates tracing messages.

Remarks

Configuration File

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

Example

The following example shows how to use the <listeners> element to add a console trace listener to the mySource source and to remove the default trace listener.

<configuration>  
  <system.diagnostics>  
    <sources>  
      <source name="mySource" switchName="sourceSwitch"   
        switchType="System.Diagnostics.SourceSwitch">  
        <listeners>  
          <add name="console"   
            type="System.Diagnostics.ConsoleTraceListener">  
            <filter type="System.Diagnostics.EventTypeFilter"   
              initializeData="Error"/>  
          </add>  
          <remove name="Default"/>  
        </listeners>  
      </source>  
    </sources>  
    <switches>  
      <add name="sourceSwitch" value="Warning"/>  
    </switches>  
  </system.diagnostics>  
</configuration>  

See Also

TraceListener
Trace and Debug Settings Schema
Trace Listeners