<source> 元素<source> Element

指定用于启动跟踪消息的跟踪源。Specifies a trace source that initiates tracing messages.




特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.


属性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. 如果未在元素中标识开关 <switches> ,则值指定开关的级别。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.

指定跟踪源特定属性的值,该属性由 GetSupportedAttributes 该跟踪源的方法标识。Specifies the value for a trace source-specific attribute identified by the GetSupportedAttributes method for that trace source.

子元素Child Elements

元素Element 描述Description
<listeners> 包含收集、存储和路由消息的侦听器。Contains listeners that collect, store, and route messages.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。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.


此元素可在计算机配置文件中使用 ( # A0) 和应用程序配置文件。This element can be used in the machine configuration file (Machine.config) and the application configuration file.


下面的示例演示如何使用 <source> 元素添加跟踪源 mySource ,并设置名为的源开关的级别 sourceSwitchThe 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.

      <source name="mySource" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch"  >  
          <add name="console" type="System.Diagnostics.ConsoleTraceListener" >  
            <filter type="System.Diagnostics.EventTypeFilter" initializeData="Error" />  
          <remove name="Default" />  
           <add name="sourceSwitch" value="Warning" />  

请参阅See also