Freigeben über


<filter> Element for <add> for <listeners> for <trace> 

Adds a filter to a listener in the Listeners collection for a trace.

<filter 
    type="traceFilterClassName" 
    initializeData="data" />

Attributes and Elements

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

Attributes

Attribute Description

type

Required attribute.

Specifies the type of the filter, which should inherit from the TraceFilter class. You can use the namespace-qualified name of the type, which corresponds to the type's FullName property, or you can use the fully qualified type name including the assembly information, which corresponds to the AssemblyQualifiedName property. For information about fully qualified type names, see Specifying Fully Qualified Type Names.

initializeData

Optional attribute.

The string passed to the constructor for the specified filter class.

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.

add

Adds a listener to the Listeners collection.

Remarks

The <filter> element must be contained in an <add> element for a trace listener that specifies the type of the listener, not just the name of a listener defined in a <sharedListeners> Element. If the listener is defined in a <sharedListeners> Element, the filter for that listener must be defined in that element.

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 <filter> element to add a filter to the listener console in the Listeners collection for trace, specifying the filter event level as Error.

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

See Also

Reference

Trace and Debug Settings Schema
Trace
TraceListener
System.Diagnostics.TraceListener.Filter
TraceFilter