Share via


<clear> Element for <listeners> for <source> 

Clears the Listeners collection for a trace source.

<clear/>

Attributes and Elements

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

Attributes

None.

Child Elements

None.

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.

listeners

Specifies listeners that collect, store, and route messages.

Remarks

The <clear> element removes all listeners from the Listeners collection for a trace source, including the DefaultTraceListener. You can use the <clear> element before using the <add> element to be certain there are no other active listeners in the collection.

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 <clear> element before using the <add> elements to add the listeners console and textListener to the Listeners collection for the trace source TraceSourceApp.

<configuration>
  <system.diagnostics>
    <sources>
       <source name="TraceSourceApp" switchName="sourceSwitch" 
         switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <clear/>
          <add name="console" 
            type="System.Diagnostics.ConsoleTraceListener"/>
          <add name="textListener"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="textListener" 
        type="System.Diagnostics.TextWriterTraceListener" 
        initializeData="myListener.log"/>
    </sharedListeners>
    <switches>
      <add name="sourceSwitch" value="Warning"/>
    </switches>
  </system.diagnostics>
</configuration> 

See Also

Reference

Trace and Debug Settings Schema
TraceSource
TraceListener

Concepts

Trace Listeners