<add> Element for <sharedListeners> 

Adds a listener to the sharedListeners collection. sharedListeners is a collection of listeners that any <source> Element or <trace> Element can reference. By default, listeners in the sharedListeners collection are not placed in a Listeners collection. They must be added by name to the <source> Element or <trace> Element. It is not possible to get the listeners in the sharedListeners collection in code at run time.

<add name="name" 
  type="TraceListenerClassName, Version, Culture, PublicKeyToken"

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


Attribute Description


Required attribute.

Specifies the name of the listener that is used to add the shared listener to a Listeners collection.


Required attribute.

Specifies the type of the listener. You must use a string that meets the requirements specified in Specifying Fully Qualified Type Names.


Optional attribute.

The string passed to the constructor for the specified class.

Child Elements

Element Description

<filter> Element for <add> for <sharedListeners>

Adds a filter to a listener in 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 trace listeners that collect, store, and route messages and the level where a trace switch is set.


A collection of listeners that any source or trace element can reference.

The listener classes shipped with the .NET Framework derive from the TraceListener class. The value for the name attribute is used to add the shared listener to a Listeners collection for either a trace or a trace source. The value for the initializeData attribute depends on the type of listener you create. Not all trace listeners require you to specify initializeData. The following table shows the trace listeners that ship with the .NET Framework and describes the value of their initializeData attributes.

Trace listener class initializeData attribute value


The useErrorStream value for the ConsoleTraceListener constructor. Set the initializeData attribute to "true" to write trace and debug output to the standard error stream; set it to "false" to write to the standard output stream.


The name of the file the DelimitedListTraceListener writes to.


The name of an existing event log source.


The name of the file that the TextWriterTraceListener writes to.


The name of the file that the XmlWriterTraceListener writes to.

This element can be used in the machine configuration file (Machine.config) and the application configuration file.

The following example shows how to use <add> elements to add the TextWriterTraceListener textListener to the sharedListeners collection. textListener is added by name to the Listeners collection for the trace source TraceSourceApp. The textListener listener writes trace output to the file myListener.log.

      <source name="TraceSourceApp" switchName="sourceSwitch" 
          <add name="console" 
          <add name="textListener"/>
          <remove name="Default"/>
      <add name="textListener" 
      <add name="sourceSwitch" value="Warning"/>