<sharedListeners> Element 

Contains listeners that any source or trace element can reference. These listeners do not receive any traces by default, and it is not possible to retrieve these listeners at run time. Listeners identified as shared listeners can be added to sources or traces by name.


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



Child Elements

Element Description

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

Adds a listener to the sharedListeners collection.

Parent Elements

Element Description


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


Specifies the root element for the ASP.NET configuration section.

Adding a listener to the shared listeners collection does not make it an active listener. It must still be added to a trace source or a trace by adding it to the Listeners collection for that trace element. The listener classes in the .NET Framework derive from the TraceListener class.

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 <sharedListeners> element to add the listener console to the Listeners collection for both the TraceSource and Trace classes. The console trace listener writes trace information to the console through calls to either TraceSource or Trace.

    <source name="mySource" switchName="sourceSwitch value="Verbose" >
        <add name="console" />
    <add name="console" type="System.Diagnostics.ConsoleTraceListener" >
      <filter type="System.Diagnostics.EventTypeFilter" 
        initializeData="Warning" />
      <add name="console" />

Community Additions