This documentation is archived and is not being maintained.

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

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

    initializeData="data" />

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


Attribute Description


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.


Optional attribute.

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

Child Elements


Parent Elements

Element Description


The root element in every configuration file used by the common language runtime and .NET Framework applications.


Specifies trace listeners that collect, store, and route messages and the level where a trace switch is set.


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


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


Adds a listener to the Listeners collection.

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.

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.

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