Export (0) Print
Expand All

EventProviderTraceListener Class

A listener for System.Diagnostics.TraceSource that writes events to the ETW subsytem.

System.Object
  System.MarshalByRefObject
    System.Diagnostics.TraceListener
      System.Diagnostics.Eventing.EventProviderTraceListener

Namespace:  System.Diagnostics.Eventing
Assembly:  System.Core (in System.Core.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public class EventProviderTraceListener : TraceListener

The EventProviderTraceListener type exposes the following members.

  NameDescription
Public methodEventProviderTraceListener(String)Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier.
Public methodEventProviderTraceListener(String, String)Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier and name of the listener.
Public methodEventProviderTraceListener(String, String, String)Initializes a new instance of the EventProviderTraceListener class using the specified provider identifier, name of the listener, and delimiter.
Top

  NameDescription
Public propertyAttributesGets the custom trace listener attributes defined in the application configuration file. (Inherited from TraceListener.)
Public propertyDelimiterGets and sets the delimiter used to delimit the event data that is written to the ETW subsystem.
Public propertyFilterGets and sets the trace filter for the trace listener. (Inherited from TraceListener.)
Public propertyIndentLevelGets or sets the indent level. (Inherited from TraceListener.)
Public propertyIndentSizeGets or sets the number of spaces in an indent. (Inherited from TraceListener.)
Public propertyIsThreadSafeGets a value indicating whether the trace listener is thread safe. (Overrides TraceListener.IsThreadSafe.)
Public propertyNameGets or sets a name for this TraceListener. (Inherited from TraceListener.)
Protected propertyNeedIndentGets or sets a value indicating whether to indent the output. (Inherited from TraceListener.)
Public propertyTraceOutputOptionsGets or sets the trace output options. (Inherited from TraceListener.)
Top

  NameDescription
Public methodCloseWhen overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Overrides TraceListener.Close().)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDispose()Releases all resources used by the TraceListener. (Inherited from TraceListener.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources. (Inherited from TraceListener.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodFail(String)Emits an error message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public methodFail(String, String)Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class. (Overrides TraceListener.Fail(String, String).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushWhen overridden in a derived class, flushes the output buffer. (Overrides TraceListener.Flush().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetSupportedAttributesGets the custom attributes supported by the trace listener. (Overrides TraceListener.GetSupportedAttributes().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTraceData(TraceEventCache, String, TraceEventType, Int32, Object)Writes trace information, a data object and event information to the listener specific output. (Overrides TraceListener.TraceData(TraceEventCache, String, TraceEventType, Int32, Object).)
Public methodTraceData(TraceEventCache, String, TraceEventType, Int32, Object[])Writes trace information, an array of data objects and event information to the listener specific output. (Overrides TraceListener.TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]).)
Public methodTraceEvent(TraceEventCache, String, TraceEventType, Int32)Writes trace and event information to the listener specific output. (Overrides TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32).)
Public methodTraceEvent(TraceEventCache, String, TraceEventType, Int32, String)Writes trace information, a message, and event information to the listener specific output. (Overrides TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String).)
Public methodTraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[])Writes trace information, a formatted array of objects and event information to the listener specific output. (Overrides TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]).)
Public methodTraceTransferWrites trace information, a message, a related activity identity and event information to the listener specific output. (Overrides TraceListener.TraceTransfer(TraceEventCache, String, Int32, String, Guid).)
Public methodWrite(Object)Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public methodWrite(String)When overridden in a derived class, writes the specified message to the listener you create in the derived class. (Overrides TraceListener.Write(String).)
Public methodWrite(Object, String)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.)
Public methodWrite(String, String)Writes a category name and a message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Protected methodWriteIndentWrites the indent to the listener you create when you implement this class, and resets the NeedIndent property to false. (Inherited from TraceListener.)
Public methodWriteLine(Object)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.)
Public methodWriteLine(String)When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator. (Overrides TraceListener.WriteLine(String).)
Public methodWriteLine(Object, String)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.)
Public methodWriteLine(String, String)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.)
Top

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. To specify a different delimiter, use the Delimiter property.

Adding the listener to System.Diagnostics.TraceSource registers the provider with the ETW subsystem. 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.

When you call the System.Diagnostics.TraceSource methods to write events, you pass a TraceEventType enumeration value. The enumeration contains both level and keyword values. 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 TraceEventType enumeration values:

  • Critical (value is 1)

  • Error (value is 2)

  • Information (value is 8)

  • Verbose (value is 16)

  • Warning (value is 4)

The keyword value that you specify for the session can be the value associated with one of the following TraceEventType enumeration values:

  • Resume (value is 2,048)

  • Start (value is 256)

  • Stop (value is 512)

  • Suspend (value is 1,024)

  • Transfer (value is 4,096)

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

        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 });

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft