Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework General Reference
<source> Element

Specifies a trace source that initiates tracing messages.

<configuration> Element
  <system.diagnostics> Element
    <sources> Element
      <source> Element
<source> 
  <listeners>...</listeners>
</source>

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

Attributes

Attribute

Description

name

Optional attribute.

Specifies the name of the trace source.

switchName

Optional attribute.

Specifies the name of a trace switch instance in the application. If the switch is not identified in a <switches> element, the value specifies the level for the switch.

switchType

Optional attribute.

Specifies the type of the trace switch. If present, the type must be a valid class name and cannot be an empty string.

extraAttribute

Optional attribute.

Specifies the value for a trace source-specific attribute identified by the GetSupportedAttributes method for that trace source.

Child Elements

Element

Description

<listeners> Element for <trace>

Contains listeners that collect, store, and route messages.

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.

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 <source> element to add the trace source mySource and to set the level for the source switch named sourceSwitch. A console trace listener is added that writes trace information to the console.

<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>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
The "name" attribute is not optional      Ken Smith   |   Edit   |   Show History
According to the documentation above, the "name" attribute is optional. However, if you leave it out, it shows up as a Warning in Visual Studio: "The required attribute 'name' is missing."
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker