Export (0) Print
Expand All

EventSource Class

.NET Framework 4.6 and 4.5

Provides the ability to create events for event tracing for Windows (ETW).

System.Object
  System.Diagnostics.Tracing.EventSource

Namespace:  System.Diagnostics.Tracing
Assemblies:   mscorlib (in mscorlib.dll)
  System.Diagnostics.Tracing (in System.Diagnostics.Tracing.dll)

type EventSource =  
    class 
        interface IDisposable 
    end

The EventSource type exposes the following members.

  NameDescription
Protected methodEventSource()Creates a new instance of the EventSource class.
Protected methodEventSource(Boolean)Creates a new instance of the EventSource class and specifies whether to throw an exception when an error occurs in the underlying Windows code.
Protected methodEventSource(EventSourceSettings)Creates a new instance of the EventSource class with the specified configuration settings.
Public methodEventSource(String)Creates a new instance of the EventSource class with the specified name.
Protected methodEventSource(EventSourceSettings, String[])Initializes a new instance of the EventSource to be used with non-contract events that contains the specified settings and traits.
Public methodEventSource(String, EventSourceSettings)Creates a new instance of the EventSource class with the specified name and settings.
Public methodEventSource(String, EventSourceSettings, String[])Creates a new instance of the EventSource class with the specified configuration settings.
Top

  NameDescription
Public propertyConstructionException[Supported in the .NET Framework 4.5.1 and later versions] Gets any exception that was thrown during the construction of the event source.
Public propertyStatic memberCurrentThreadActivityId[Supported in the .NET Framework 4.5.1 and later versions] Gets the activity ID of the current thread.
Public propertyGuidThe unique identifier for the event source.
Public propertyNameThe friendly name of the class that is derived from the event source.
Public propertySettingsGets the settings applied to this event source.
Top

  NameDescription
Public methodDispose()Releases all resources used by the current instance of the EventSource class.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the EventSource class and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows the EventSource object to attempt to free resources and perform other cleanup operations before the object is reclaimed by garbage collection. (Overrides Object.Finalize().)
Public methodStatic memberGenerateManifest(Type, String)Returns a string of the XML manifest that is associated with the current event source.
Public methodStatic memberGenerateManifest(Type, String, EventManifestOptions)Returns a string of the XML manifest that is associated with the current event source.
Public methodStatic memberGetGuidGets the unique identifier for this implementation of the event source.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodStatic memberGetNameGets the friendly name of the event source.
Public methodStatic memberGetSourcesGets a snapshot of all the event sources for the application domain.
Public methodGetTraitGets the trait value associated with the specified key.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsEnabled()Determines whether the current event source is enabled.
Public methodIsEnabled(EventLevel, EventKeywords)Determines whether the current event source that has the specified level and keyword is enabled.
Public methodIsEnabled(EventLevel, EventKeywords, EventChannel)Determines whether the current event source is enabled for events with the specified level, keywords and channel.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnEventCommandCalled when the current event source is updated by the controller.
Public methodStatic memberSendCommandSends a command to a specified event source.
Public methodStatic memberSetCurrentThreadActivityId(Guid)[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread.
Public methodStatic memberSetCurrentThreadActivityId(Guid, Guid)[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread, and returns the previous activity ID.
Public methodToStringObtains a string representation of the current event source instance. (Overrides Object.ToString().)
Public methodWrite(String)Writes an event without fields, but with the specified name and default options.
Public methodWrite(String, EventSourceOptions)Writes an event without fields, but with the specified name and options.
Public methodWrite(T)(String, T)Writes an event with the specified name and data.
Public methodWrite(T)(String, EventSourceOptions, T)Writes an event with the specified name, event data and options.
Public methodWrite(T)(String, EventSourceOptions, T)Writes an event with the specified name, options and event data.
Public methodWrite(T)(String, EventSourceOptions, Guid, Guid, T)Writes an event with the specified name, options, related activity and event data.
Protected methodWriteEvent(Int32)Writes an event by using the provided event identifier.
Protected methodWriteEvent(Int32, Byte[])Writes an event by using the provided event identifier and byte array argument.
Protected methodWriteEvent(Int32, Int32)Writes an event by using the provided event identifier and 32-bit integer argument.
Protected methodWriteEvent(Int32, Int64)Writes an event by using the provided event identifier and 64-bit integer argument.
Protected methodWriteEvent(Int32, Object[])Writes an event by using the provided event identifier and array of arguments.
Protected methodWriteEvent(Int32, String)Writes an event by using the provided event identifier and string argument.
Protected methodWriteEvent(Int32, Int32, Int32)Writes an event by using the provided event identifier and 32-bit integer arguments.
Protected methodWriteEvent(Int32, Int32, String)Writes an event by using the provided event identifier and 32-bit integer and string arguments.
Protected methodWriteEvent(Int32, Int64, Byte[])Writes the event data using the specified indentifier and 64-bit integer and byte array arguments.
Protected methodWriteEvent(Int32, Int64, Int64)Writes an event by using the provided event identifier and 64-bit arguments.
Protected methodWriteEvent(Int32, Int64, String)Writes an event by using the provided event identifier and 64-bit integer, and string arguments.
Protected methodWriteEvent(Int32, String, Int32)Writes an event by using the provided event identifier and arguments.
Protected methodWriteEvent(Int32, String, Int64)Writes an event by using the provided event identifier and arguments.
Protected methodWriteEvent(Int32, String, String)Writes an event by using the provided event identifier and string arguments.
Protected methodWriteEvent(Int32, Int32, Int32, Int32)Writes an event by using the provided event identifier and 32-bit integer arguments.
Protected methodWriteEvent(Int32, Int64, Int64, Int64)Writes an event by using the provided event identifier and 64-bit arguments.
Protected methodWriteEvent(Int32, String, Int32, Int32)Writes an event by using the provided event identifier and arguments.
Protected methodWriteEvent(Int32, String, String, String)Writes an event by using the provided event identifier and string arguments.
Protected methodWriteEventCoreCreates a new WriteEvent overload by using the provided event identifier and event data.
Protected methodWriteEventWithRelatedActivityId[Supported in the .NET Framework 4.5.1 and later versions] Writes an event that indicates that the current activity is related to another activity.
Protected methodWriteEventWithRelatedActivityIdCore[Supported in the .NET Framework 4.5.1 and later versions] Writes an event that indicates that the current activity is related to another activity.
Top

This class is intended to be inherited by a user class that provides specific events to be used for ETW. The EventSource.WriteEvent methods are called to log the events.

Important noteImportant

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

The basic functionality of EventSource is sufficient for most applications. If you want more control over the ETW manifest that is created, you can apply the EventAttribute attribute to the methods. For advanced event source applications, it is possible to intercept the commands being sent to the derived event source and change the filtering, or to cause actions (such as dumping a data structure) to be performed by the inheritor. An event source can be activated with Windows ETW controllers, such as the Logman tool, immediately. It is also possible to programmatically control and intercept the data dispatcher. The EventListener class provides additional functionality.

Starting with .NET Framework 4.6 RC, EventSource provides channel support and some of the event source validation rules have been relaxed. This means:

  • EventSource types may now implement interfaces. This enables the use of event source types in advanced logging systems that use interfaces to define a common logging target.

  • The concept of a utility event source type has been introduced. This feature enables sharing code across multiple event source types in a project to enable scenarios such as optimized WriteEvent overloads.

For a version of the EventSource class that provides features such as channel support you are targeting .NET Framework 4.5.1 or earlier, see Microsoft EventSource Library 1.0.16.

The following example shows a simple implementation of the EventSource class.

No code example is currently available or this language may not be supported.

The following example shows a more complex implementation of the EventSource class.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5

Supported in: Windows Phone 8.1

This type is thread safe.

Show:
© 2015 Microsoft