Share via


<clear> Element for <listeners> for <trace>

Clears the Listeners collection for trace.

<configuration> Element
  <system.diagnostics> Element
    <trace> Element
      <listeners> Element for <trace>
        <clear> Element for <listeners> for <trace>

<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.

trace

Contains listeners that collect, store, and route tracing messages.

listeners

Contains listeners that collect, store, and route messages. Listeners direct the tracing output to an appropriate target.

Remarks

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

You can clear the Listeners collection programmatically by calling the Clear method on the Trace.Listeners property (System.Diagnostics.Trace.Listeners.Clear()).

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

Note

The <clear> element removes the DefaultTraceListener from the Listeners collection, altering the behavior of the Debug.Assert, Trace.Assert, Debug.Fail, and Trace.Fail methods. Calling an Assert or Fail method normally results in the display of a message box. However, the message box is not displayed if the DefaultTraceListener is not in the Listeners collection.

Example

The following example shows how to use the <clear> element before using the <add> element to add the listener console to the Listeners collection for trace.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <clear/>
        <add name="console" 
          type="System.Diagnostics.ConsoleTraceListener" >
          <filter type="System.Diagnostics.EventTypeFilter" 
            initializeData="Error" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration> 

See Also

Reference

Trace and Debug Settings Schema

<remove> Element for <listeners> for <trace>

Listeners

Trace

Debug

TraceSource

Concepts

Trace Listeners