<sources> 元素<sources> Element

指定启动跟踪消息的跟踪源。Specifies trace sources that initiate tracing messages.




特性和元素Attributes and Elements

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



子元素Child Elements

元素Element 描述Description
<source> 必需的元素。Required element.

指定用于启动跟踪消息的跟踪源。Specifies a trace source that initiates tracing 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.


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


下面的示例演示如何使用 <sources> 元素添加跟踪源 mySource ,并设置名为的源开关的级别 sourceSwitchThe following example shows how to use the <sources> 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