<clear>的元素 <listeners><source><clear> Element for <listeners> for <source>

清除跟踪源的 Listeners 集合。Clears the Listeners collection for a trace source.

<configuration>
  <system.diagnostics>
    <sources>
      <source>
        <listeners>
          <clear>

语法Syntax

<clear/>  

特性和元素Attributes and Elements

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

特性Attributes

无。None.

子元素Child Elements

无。None.

父元素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.
source 指定用于启动跟踪消息的跟踪源。Specifies a trace source that initiates tracing messages.
listeners 指定用于收集、存储和路由消息的侦听器。Specifies listeners that collect, store, and route messages.

备注Remarks

<clear>元素从跟踪源的集合中移除所有侦听器 Listeners ,包括 DefaultTraceListenerThe <clear> element removes all listeners from the Listeners collection for a trace source, including the DefaultTraceListener. 可以在使用元素 <clear> 之前使用元素 <add> ,以确定集合中没有其他活动的侦听器。You can use the <clear> element before using the <add> element to be certain there are no other active listeners in the collection.

配置文件Configuration File

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

示例Example

下面的示例演示如何 <clear> 在使用 <add> 元素将侦听器 consoletextListener 集合添加到 Listeners 跟踪源之前使用元素 TraceSourceAppThe following example shows how to use the <clear> element before using the <add> elements to add the listeners console and textListener to the Listeners collection for the trace source TraceSourceApp.

<configuration>  
  <system.diagnostics>  
    <sources>  
       <source name="TraceSourceApp" switchName="sourceSwitch"
         switchType="System.Diagnostics.SourceSwitch">  
        <listeners>  
          <clear/>  
          <add name="console"
            type="System.Diagnostics.ConsoleTraceListener"/>  
          <add name="textListener"/>  
        </listeners>  
      </source>  
    </sources>  
    <sharedListeners>  
      <add name="textListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="myListener.log"/>  
    </sharedListeners>  
    <switches>  
      <add name="sourceSwitch" value="Warning"/>  
    </switches>  
  </system.diagnostics>  
</configuration>

请参阅See also