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

在的集合中添加或移除侦听器 Listeners TraceSourceAdds 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.



  <remove ... />  

特性和元素Attributes and Elements

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



子元素Child Elements

元素Element 说明Description
<add> 将侦听器添加到 Listeners 集合中。Adds a listener to the Listeners collection.
<remove> 从集合中移除侦听器 ListenersRemoves a listener from the Listeners collection.
<clear> 清除跟踪源的 Listeners 集合。Clears the Listeners collection for a trace source.

父元素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.


配置文件Configuration File

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


下面的示例演示如何使用 <listeners> 元素将控制台跟踪侦听器添加到 mySource 源,并删除默认的跟踪侦听器。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.

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

另请参阅See also