EventSource Constructors

Definition

Creates a new instance of the EventSource class.

Overloads

EventSource()

Creates a new instance of the EventSource class.

EventSource(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.

EventSource(EventSourceSettings)

Creates a new instance of the EventSource class with the specified configuration settings.

EventSource(String)

Creates a new instance of the EventSource class with the specified name.

EventSource(EventSourceSettings, String[])

Initializes a new instance of the EventSource to be used with non-contract events that contains the specified settings and traits.

EventSource(String, EventSourceSettings)

Creates a new instance of the EventSource class with the specified name and settings.

EventSource(String, EventSourceSettings, String[])

Creates a new instance of the EventSource class with the specified configuration settings.

EventSource()

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Creates a new instance of the EventSource class.

C#
protected EventSource();

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(Boolean)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Creates a new instance of the EventSource class and specifies whether to throw an exception when an error occurs in the underlying Windows code.

C#
protected EventSource(bool throwOnEventWriteErrors);

Parameters

throwOnEventWriteErrors
Boolean

true to throw an exception when an error occurs in the underlying Windows code; otherwise, false.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(EventSourceSettings)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Creates a new instance of the EventSource class with the specified configuration settings.

C#
protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings);

Parameters

settings
EventSourceSettings

A bitwise combination of the enumeration values that specify the configuration settings to apply to the event source.

Remarks

Specifying settings when the EventSource is constructed enables you to specify whether the event is written in a manifest-based or a self-describing format. In addition, you can specify that an exception should be raised when an error occurs during the event-writing process.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(String)

Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs

Creates a new instance of the EventSource class with the specified name.

C#
public EventSource(string eventSourceName);

Parameters

eventSourceName
String

The name to apply to the event source. Must not be null.

Exceptions

eventSourceName is null.

Remarks

When using this constructor, ensure that the eventSourceName argument matches the ETW name defined by the EventSourceAttribute attribute on that type. Otherwise, the GUIDs returned by the Guid property and the GetGuid(Type) method will be different. If the event source names differ, the Guid property returns the GUID used to register this EventSource with ETW.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(EventSourceSettings, String[])

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Initializes a new instance of the EventSource to be used with non-contract events that contains the specified settings and traits.

C#
protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings, params string[] traits);
C#
protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings, params string[]? traits);

Parameters

settings
EventSourceSettings

A bitwise combination of the enumeration values that specify the configuration settings to apply to the event source.

traits
String[]

The key-value pairs that specify traits for the event source.

Exceptions

traits is not specified in key-value pairs.

Remarks

Traits provide additional information for an event and are interpreted by an event listener. Traits are specified as key-value pairs and if not specified in pairs, an exception will occur. You can retrieve a trait by passing the key to the GetTrait, method.

Specifying settings when the EventSource is constructed enables you to specify whether the event is written in a manifest-based or a self-describing format. In addition, you can specify that an exception should be raised when an error occurs during the event-writing process.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(String, EventSourceSettings)

Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs

Creates a new instance of the EventSource class with the specified name and settings.

C#
public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config);

Parameters

eventSourceName
String

The name to apply to the event source. Must not be null.

config
EventSourceSettings

A bitwise combination of the enumeration values that specify the configuration settings to apply to the event source.

Exceptions

eventSourceName is null.

Remarks

Specifying settings when the EventSource is constructed enables you to specify whether the event is written in a manifest-based or a self-describing format. In addition, you can specify that an exception should be raised when an error occurs during the event-writing process.

When using this constructor, ensure that the eventSourceName argument matches the ETW name defined by the EventSourceAttribute attribute on that type. Otherwise, the GUIDs returned by the Guid property and the GetGuid(Type) method will be different.

In such cases, the Guid property returns the GUID used to register this EventSource with ETW.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

EventSource(String, EventSourceSettings, String[])

Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs
Source:
TraceLoggingEventSource.cs

Creates a new instance of the EventSource class with the specified configuration settings.

C#
public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config, params string[] traits);
C#
public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config, params string[]? traits);

Parameters

eventSourceName
String

The name to apply to the event source. Must not be null.

config
EventSourceSettings

A bitwise combination of the enumeration values that specify the configuration settings to apply to the event source.

traits
String[]

The key-value pairs that specify traits for the event source.

Exceptions

eventSourceName is null.

traits is not specified in key-value pairs.

Remarks

Traits provide additional information for an event and are interpreted by an event listener. Traits are specified as key-value pairs and if not specified in pairs, an exception will occur. You can retrieve a trait by passing the key to the GetTrait, method.

Specifying config when the EventSource is constructed enables you to specify whether the event is written in a manifest-based or a self-describing format. In addition, you can specify that an exception should be raised when an error occurs during the event-writing process.

When using this constructor, ensure that the eventSourceName argument matches the ETW name defined by the EventSourceAttribute attribute on that type. Otherwise, the GUIDs returned by the Guid property and the GetGuid(Type) method will be different.

In such cases, the GUID used to register this EventSource with ETW is the one returned by Guid.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0