EventProviderTraceListener EventProviderTraceListener EventProviderTraceListener EventProviderTraceListener Class

定義

TraceSource 的接聽項,其負責將事件寫入至 ETW 子系統。A listener for TraceSource that writes events to the ETW subsystem.

public ref class EventProviderTraceListener : System::Diagnostics::TraceListener
public class EventProviderTraceListener : System.Diagnostics.TraceListener
type EventProviderTraceListener = class
    inherit TraceListener
Public Class EventProviderTraceListener
Inherits TraceListener
繼承
EventProviderTraceListenerEventProviderTraceListenerEventProviderTraceListenerEventProviderTraceListener

範例

private static Guid providerId = new Guid("{B3F0C8FC-E8A8-4868-8901-1465E8A2F41B}");  

    EventProviderTraceListener listener = new EventProviderTraceListener(providerId.ToString(), "Test Listener", "::");  

    // You should use the All default level and control the level using the  
    // ETW session; otherwise, you may not log all the events requested by the  
    // session.  
    TraceSource source = new TraceSource("MyProvider", SourceLevels.All);  

    source.Listeners.Add(listener);  

    source.TraceData(TraceEventType.Warning | TraceEventType.Start, 2, new object[] { "abc", "def", true, 123 });  

    source.TraceEvent(TraceEventType.Warning, 12, "Provider guid: {0}", new object[] { providerId });  

    source.TraceInformation("string {0}, bool {1}, int {2}, ushort {3}", new object[] { "abc", false, 123, (UInt32)5 });  

備註

來自來源事件的所有事件資料 (追蹤或 debug) 都會以字串的形式寫入 ETW 子系統。All event data (trace or debug) from the source event is written to the ETW subsystem as a string. 資料元素是使用逗號分隔。The data elements are delimited using a comma. 若要指定不同的分隔符號, 請Delimiter使用屬性。To specify a different delimiter, use the Delimiter property.

新增接聽程式, System.Diagnostics.TraceSource以向 ETW 子系統註冊提供者。Adding the listener to System.Diagnostics.TraceSource registers the provider with the ETW subsystem. 您必須使用 Logman 可執行程式 (或類似的專案) 來建立 ETW 追蹤會話, 才能將事件寫入記錄檔。You must create an ETW trace session using the Logman.exe executable program (or something similar) to write the events to a log file.

您不需要使用來自接聽程式之事件的資訊清單, 因為事件資料是單一字串。You do not need a manifest to consume events from the listener because the event data is a single string.

當您呼叫System.Diagnostics.TraceSource方法來寫入事件時, 您會System.Diagnostics.TraceEventType傳遞列舉值。When you call the System.Diagnostics.TraceSource methods to write events, you pass a System.Diagnostics.TraceEventType enumeration value. 列舉同時包含 level 和關鍵字值。The enumeration contains both level and keyword values. 當您從 ETW 會話啟用追蹤接聽項提供者時, 您指定的層級值可以是與下列System.Diagnostics.TraceEventType其中一個列舉值相關聯的值:When you enable a trace listener provider from an ETW session, the level value that you specify can be the value associated with one of the following System.Diagnostics.TraceEventType enumeration values:

  • 重大 (值為 1)Critical (value is 1)

  • 錯誤 (值為 2)Error (value is 2)

  • 資訊 (值為 8)Information (value is 8)

  • 詳細資訊 (值為 16)Verbose (value is 16)

  • 警告 (值為 4)Warning (value is 4)

您為會話指定的關鍵字值可以是與下列System.Diagnostics.TraceEventType其中一個列舉值相關聯的值:The keyword value that you specify for the session can be the value associated with one of the following System.Diagnostics.TraceEventType enumeration values:

  • Resume (值為 2048)Resume (value is 2,048)

  • Start (值為 256)Start (value is 256)

  • 停止 (值為 512)Stop (value is 512)

  • 暫止 (值為 1024)Suspend (value is 1,024)

  • 轉移 (值為 4096)Transfer (value is 4,096)

建構函式

EventProviderTraceListener(String) EventProviderTraceListener(String) EventProviderTraceListener(String) EventProviderTraceListener(String)

使用指定的提供者識別項,初始化 EventProviderTraceListener 類別的新執行個體。Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier.

EventProviderTraceListener(String, String) EventProviderTraceListener(String, String) EventProviderTraceListener(String, String) EventProviderTraceListener(String, String)

使用指定的提供者識別項和接聽項的名稱,初始化 EventProviderTraceListener 類別的新執行個體。Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier and name of the listener.

EventProviderTraceListener(String, String, String) EventProviderTraceListener(String, String, String) EventProviderTraceListener(String, String, String) EventProviderTraceListener(String, String, String)

使用指定的提供者識別項、接聽項的名稱和分隔符號,初始化 EventProviderTraceListener 類別的新執行個體。Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier, name of the listener, and delimiter.

屬性

Attributes Attributes Attributes Attributes

取得在應用程式組態檔中定義的自訂追蹤接聽程式屬性。Gets the custom trace listener attributes defined in the application configuration file.

(Inherited from TraceListener)
Delimiter Delimiter Delimiter Delimiter

取得或設定用來分隔寫入至 ETW 子系統事件資料的分隔符號。Gets or sets the delimiter used to delimit the event data that is written to the ETW subsystem.

Filter Filter Filter Filter

取得或設定追蹤接聽程式的追蹤篩選。Gets or sets the trace filter for the trace listener.

(Inherited from TraceListener)
IndentLevel IndentLevel IndentLevel IndentLevel

取得或設定縮排層級。Gets or sets the indent level.

(Inherited from TraceListener)
IndentSize IndentSize IndentSize IndentSize

取得或設定縮排的空格數目。Gets or sets the number of spaces in an indent.

(Inherited from TraceListener)
IsThreadSafe IsThreadSafe IsThreadSafe IsThreadSafe

取得值,指出追蹤接聽程式是否為執行緒安全。Gets a value indicating whether the trace listener is thread safe.

Name Name Name Name

取得或設定這個 TraceListener 的名稱。Gets or sets a name for this TraceListener.

(Inherited from TraceListener)
NeedIndent NeedIndent NeedIndent NeedIndent

取得或設定值,指出是否要縮排輸出。Gets or sets a value indicating whether to indent the output.

(Inherited from TraceListener)
TraceOutputOptions TraceOutputOptions TraceOutputOptions TraceOutputOptions

取得或設定追蹤輸出選項。Gets or sets the trace output options.

(Inherited from TraceListener)

方法

Close() Close() Close() Close()

關閉輸出資料流,使它不再接收追蹤或偵錯輸出。Closes the output stream so it no longer receives tracing or debugging output.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

釋放 TraceListener 所使用的所有資源。Releases all resources used by the TraceListener.

(Inherited from TraceListener)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 TraceListener 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources.

(Inherited from TraceListener)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Fail(String) Fail(String) Fail(String) Fail(String)

當您實作 TraceListener 類別時,發出錯誤訊息給您建立的接聽項。Emits an error message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Fail(String, String) Fail(String, String) Fail(String, String) Fail(String, String)

當您實作 TraceListener 類別時,發出錯誤訊息和詳細的錯誤訊息給您建立的接聽程式。Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class.

Flush() Flush() Flush() Flush()

排清輸出緩衝區。Flushes the output buffer.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes()

取得由追蹤接聽程式支援的自訂屬性。Gets the custom attributes supported by the trace listener.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TraceData(TraceEventCache, String, TraceEventType, Int32, Object) TraceData(TraceEventCache, String, TraceEventType, Int32, Object) TraceData(TraceEventCache, String, TraceEventType, Int32, Object) TraceData(TraceEventCache, String, TraceEventType, Int32, Object)

寫入追蹤資訊,資料物件,及事件資訊至特定接聽程式的輸出。Writes trace information, a data object and event information to the listener specific output.

TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) TraceData(TraceEventCache, String, TraceEventType, Int32, Object[])

寫入追蹤資訊,資料物件,及事件資訊至特定接聽程式的輸出。Writes trace information, a data object and event information to the listener specific output.

TraceEvent(TraceEventCache, String, TraceEventType, Int32) TraceEvent(TraceEventCache, String, TraceEventType, Int32) TraceEvent(TraceEventCache, String, TraceEventType, Int32) TraceEvent(TraceEventCache, String, TraceEventType, Int32)

寫入追蹤和事件資訊至特定接聽程式的輸出。Writes trace and event information to the listener specific output.

TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String)

寫入追蹤資訊,訊息,及事件資訊至特定接聽程式的輸出。Writes trace information, a message, and event information to the listener specific output.

TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[])

寫入追蹤資訊,格式化的物件陣列,及事件資訊至特定接聽程式的輸出。Writes trace information, a formatted array of objects and event information to the listener specific output.

TraceTransfer(TraceEventCache, String, Int32, String, Guid) TraceTransfer(TraceEventCache, String, Int32, String, Guid) TraceTransfer(TraceEventCache, String, Int32, String, Guid) TraceTransfer(TraceEventCache, String, Int32, String, Guid)

寫入追蹤資訊、訊息、相關活動識別,及事件資訊至特定接聽程式的輸出。Writes trace information, a message, a related activity identity and event information to the listener specific output.

Write(Object) Write(Object) Write(Object) Write(Object)

將物件的 ToString() 方法的值寫入當您實作 TraceListener 類別時所建立的接聽項。Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Write(Object, String) Write(Object, String) Write(Object, String) Write(Object, String)

將分類名稱和物件的 ToString() 方法的值寫入當您實作 TraceListener 類別時所建立的接聽項。Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Write(String) Write(String) Write(String) Write(String)

當在衍生類別中覆寫時,將指定的訊息寫入您在衍生類別中建立的接聽程式。When overridden in a derived class, writes the specified message to the listener you create in the derived class.

Write(String, String) Write(String, String) Write(String, String) Write(String, String)

將分類名稱和訊息寫入當您實作 TraceListener 類別時所建立的接聽項。Writes a category name and a message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
WriteIndent() WriteIndent() WriteIndent() WriteIndent()

將縮排寫入當您實作這個類別時所建立的接聽項,並且將 NeedIndent 屬性重設為 falseWrites the indent to the listener you create when you implement this class, and resets the NeedIndent property to false.

(Inherited from TraceListener)
WriteLine(Object) WriteLine(Object) WriteLine(Object) WriteLine(Object)

將物件的 ToString() 方法的值寫入當您實作 TraceListener 類別時所建立的接聽項,後面跟隨著行結束字元。Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator.

(Inherited from TraceListener)
WriteLine(Object, String) WriteLine(Object, String) WriteLine(Object, String) WriteLine(Object, String)

將分類名稱和物件的 ToString() 方法的值寫入當您實作 TraceListener 類別時所建立的接聽項,後面跟隨著行結束字元。Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator.

(Inherited from TraceListener)
WriteLine(String) WriteLine(String) WriteLine(String) WriteLine(String)

當在衍生類別中覆寫時,將訊息寫入您在衍生類別中所建立的接聽程式,後面跟隨著行結束字元。When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator.

WriteLine(String, String) WriteLine(String, String) WriteLine(String, String) WriteLine(String, String)

將分類名稱和訊息寫入當您實作 TraceListener 類別時所建立的接聽項,後面跟隨著行結束字元。Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.

(Inherited from TraceListener)

適用於

另請參閱