用於 <trace> 的 <listeners> 元素

指定收集、儲存及路由訊息的接聽程式。 接聽程式會將追蹤輸出導向至適當的目標。

<configuration>
  <system.diagnostics>
    <trace>
      <listeners>

Syntax

<listeners>
  <add>...</add>  
  <clear/>  
  <remove ... />  
</listeners>  

屬性和項目

下列章節說明屬性、子元素和父元素。

屬性

無。

子元素

元素 描述
<add> 將接聽項新增至 Listeners 集合。
<clear> 清除追蹤的 Listeners 集合。
<remove> Listeners 集合移除接聽程式。

父項目

元素 Description
configuration 通用語言執行平台和 .NET Framework 應用程式所使用之每個組態檔中的根項目。
system.diagnostics 指定 ASP.NET 組態區段的根項目。
trace 包含用於收集、儲存及路由傳送追蹤訊息的接聽項。

備註

DebugTrace 類別會共用相同的 Listeners 集合。 如果您將接聽程式物件加入其中一個類別的集合,另一類別會使用相同的接聽程式。 隨附于 .NET Framework 的接聽程式類別衍生自 TraceListener 類別。

組態檔

這個元素可用於機器組態檔 (Machine.config) 及應用程式組態檔。

範例

下列範例將示範如何使用 <listeners> 元素將接聽程式MyListenerMyEventListener 加入至 Listeners 集合。 MyListener 會建立名為 MyListener.log 的檔案,並將輸出寫入檔案。 MyEventListener 會在事件記錄檔建立輸入。

<configuration>  
  <system.diagnostics>  
    <trace autoflush="true" indentsize="0">  
      <listeners>  
        <add name="myListener"
          type="System.Diagnostics.TextWriterTraceListener,
            system, version=1.0.3300.0, Culture=neutral,
            PublicKeyToken=b77a5c561934e089"
          initializeData="c:\myListener.log" />  
        <add name="MyEventListener"  
          type="System.Diagnostics.EventLogTraceListener,
            system, version=1.0.3300.0, Culture=neutral,
            PublicKeyToken=b77a5c561934e089"  
          initializeData="MyConfigEventLog"/>  
      </listeners>  
    </trace>  
  </system.diagnostics>  
</configuration>  

另請參閱