EventSource.Write Method

Definition

Writes an event.

Overloads

Write(String)

Writes an event without fields, but with the specified name and default options.

Write(String, EventSourceOptions)

Writes an event without fields, but with the specified name and options.

Write<T>(String, T)

Writes an event with the specified name and data.

Write<T>(String, EventSourceOptions, T)

Writes an event with the specified name, event data and options.

Write<T>(String, EventSourceOptions, T)

Writes an event with the specified name, options and event data.

Write<T>(String, EventSourceOptions, Guid, Guid, T)

Writes an event with the specified name, options, related activity and event data.

Write(String)

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

Writes an event without fields, but with the specified name and default options.

C#
public void Write(string eventName);
C#
public void Write(string? eventName);

Parameters

eventName
String

The name of the event to write.

Exceptions

eventName is null.

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

Write(String, EventSourceOptions)

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

Writes an event without fields, but with the specified name and options.

C#
public void Write(string eventName, System.Diagnostics.Tracing.EventSourceOptions options);
C#
public void Write(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options);

Parameters

eventName
String

The name of the event to write.

options
EventSourceOptions

The options such as level, keywords and operation code for the event.

Exceptions

eventName is null.

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

Write<T>(String, T)

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

Writes an event with the specified name and data.

C#
public void Write<T>(string eventName, T data);
C#
public void Write<T>(string? eventName, T data);

Type Parameters

T

The type that defines the event and its associated data. This type must be an anonymous type or marked with the EventSourceAttribute attribute.

Parameters

eventName
String

The name of the event.

data
T

The event data. This type must be an anonymous type or marked with the EventDataAttribute attribute.

Remarks

If eventName is null, the event name is automatically derived from the type T's event data (Name) or determined based on the name of type T. The public instance properties of data will be written recursively to create the event fields.

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

Write<T>(String, EventSourceOptions, T)

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

Writes an event with the specified name, event data and options.

C#
public void Write<T>(string eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data);
C#
public void Write<T>(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data);

Type Parameters

T

The type that defines the event and its associated data. This type must be an anonymous type or marked with the EventSourceAttribute attribute.

Parameters

eventName
String

The name of the event.

options
EventSourceOptions

The event options.

data
T

The event data. This type must be an anonymous type or marked with the EventDataAttribute attribute.

Remarks

If eventName is null, the event name is automatically derived from the type T's event data (Name) or determined based on the name of type T. The public instance properties of data will be written recursively to create the event fields.

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

Write<T>(String, EventSourceOptions, T)

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

Writes an event with the specified name, options and event data.

C#
public void Write<T>(string eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data);
C#
public void Write<T>(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data);

Type Parameters

T

The type that defines the event and its associated data. This type must be an anonymous type or marked with the EventSourceAttribute attribute.

Parameters

eventName
String

The name of the event.

options
EventSourceOptions

The event options.

data
T

The event data. This type must be an anonymous type or marked with the EventDataAttribute attribute.

Remarks

If eventName is null, the event name is automatically derived from the type T's event data (Name) or determined based on the name of type T. The public instance properties of data will be written recursively to create the event fields.

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

Write<T>(String, EventSourceOptions, Guid, Guid, T)

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

Writes an event with the specified name, options, related activity and event data.

C#
public void Write<T>(string eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref Guid activityId, ref Guid relatedActivityId, ref T data);
C#
public void Write<T>(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref Guid activityId, ref Guid relatedActivityId, ref T data);

Type Parameters

T

The type that defines the event and its associated data. This type must be an anonymous type or marked with the EventSourceAttribute attribute.

Parameters

eventName
String

The name of the event.

options
EventSourceOptions

The event options.

activityId
Guid

The ID of the activity associated with the event.

relatedActivityId
Guid

The ID of an associated activity, or Empty if there is no associated activity.

data
T

The event data. This type must be an anonymous type or marked with the EventDataAttribute attribute.

Remarks

If eventName is null, the event name is automatically derived from the type T's event data (Name) or determined based on the name of type T. The public instance properties of data will be written recursively to create the event fields.

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