<filter> Element for <add> for <listeners> for <source>

 

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

<configuration>
<system.diagnostics>
<sources>
<source>
<listeners>
<add>
<filter>

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

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

Attributes

AttributeDescription
typeRequired 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.
initializeDataOptional attribute.

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

Child Elements

None.

Parent Elements

ElementDescription
configurationThe root element in every configuration file used by the common language runtime and .NET Framework applications.
system.diagnosticsSpecifies trace listeners that collect, store, and route messages and the level where a trace switch is set.
sourcesContains trace sources that initiate tracing messages.
sourceSpecifies a trace source that initiates tracing messages.
listenersContains listeners that collect, store, and route messages. Listeners direct the tracing output to an appropriate target.
addAdds a listener to the Listeners collection for a trace source.

The <filter> element must be contained in an <add> element for a trace source listener that specifies the type of the listener, not just the name of a listener defined in a <sharedListeners>. If the listener is defined in a <sharedListeners>, 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 the trace source myTraceSource, specifying the filter event level as Error.

<configuration>  
  <system.diagnostics>  
    <sources>  
      <source name="myTraceSource" 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>  

TraceSource
TraceListener
TraceListener.Filter
TraceFilter
Trace and Debug Settings Schema

Show: