<listeners> Element for <source>
Adds or removes listeners in the Listeners collection for a TraceSource. A listener directs the tracing output to an appropriate target, such as a log, window, or text file.
<system.diagnostics> Element
<sources> Element
<source> Element
<listeners> Element for <source>
<listeners> <add>...</add> <remove ... /> <clear/> </listeners>
The following sections describe attributes, child elements, and parent elements.
Attributes
None.
Child Elements
Element | Description |
|---|---|
Adds a listener to the Listeners collection. | |
Removes a listener from the Listeners collection. | |
Clears the Listeners collection for a trace source. |
Parent Elements
Element | Description |
|---|---|
configuration | The root element in every configuration file used by the common language runtime and .NET Framework applications. |
system.diagnostics | Specifies trace listeners that collect, store, and route messages and the level where a trace switch is set. |
sources | Contains trace sources that initiate tracing messages. |
source | Specifies a trace source that initiates tracing messages. |
The following example shows how to use the <listeners> element to add a console trace listener to the mySource source and to remove the default trace listener.
<configuration>
<system.diagnostics>
<sources>
<source name="mySource" 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>