This documentation is archived and is not being maintained.

<sharedListeners> Element

Updated: September 2008

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.

<configuration> Element
  <system.diagnostics> Element
    <sharedListeners> Element

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



Child Elements



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

Adds a listener to the sharedListeners collection.

Parent Elements




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.

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




September 2008

Updated the example to correct a problem with setting the value.

Customer feedback.