EventProvider.WriteEvent Method

Definition

Writes an event.

Overloads

WriteEvent(EventDescriptor, Object[])

Writes an event. The event data is specified as an array of objects.

WriteEvent(EventDescriptor, String)

Writes an event. The event data is specified as a string.

WriteEvent(EventDescriptor, Int32, IntPtr)

Writes an event. The event data is specified as a block of memory.

Remarks

Use these methods if you use a manifest to define your events.

WriteEvent(EventDescriptor, Object[])

Writes an event. The event data is specified as an array of objects.

C#
[System.Security.SecurityCritical]
public bool WriteEvent(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, params object[] eventPayload);
C#
public bool WriteEvent(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, params object[] eventPayload);

Parameters

eventDescriptor
EventDescriptor

An instance of EventDescriptor that identifies the event to write.

eventPayload
Object[]

An array of objects that contain the event data to write. The object must be in the order specified in the manifest. The array is limited to 32 objects, of which only eight may be strings. The maximum data size for the event is limited to 64 KB minus the size of the event headers. The event size is less if the session's buffer size is less and the session includes extended data items with the event.

This parameter can be null.

Returns

Is true if the event is written; otherwise, false. If false, call the GetLastWriteEventError() method to determine the cause of the failure.

Attributes

Exceptions

The eventPayload parameter contains too many objects or strings.

Examples

C#
private static Guid providerId = new Guid("{FB33FDA8-45FB-4df0-8A55-EEB4BA88E7E7}");  

enum Keyword  
{  
    Read = 0x1,  
    Write = 0x2,  
    Local = 0x4,  
    Remote = 0x8  
}  

enum Level  
{  
    Critical = 1,  
    Error,  
    Warning,  
    Information,  
    Verbose  
}  

    EventProvider provider = new EventProvider(providerId);  
    EventDescriptor readEvent;  
    string path = @"<PATHGOESHERE>";  
    UInt64 bytesRead = <ASSIGNVALUE>;  

    if (provider.IsEnabled(Level.Information, (long)Keyword.Read))  
    {  
        unchecked  
        {  
            readEvent = new EventDescriptor(0x1, 0x0, 0x10, 0x4, 0x0, 0x0, (long)0x8000000000000005);  
        }  

        if (!provider.WriteEvent(ref readEvent, new object[] { path, bytesRead }))  
            Console.WriteLine(EventProvider.GetLastWriteEventError());  
    }  

    provider.Close();  

Remarks

If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.

If the object type is not supported, the method writes the value of the object's Object.ToString method in the payload. For a list of supported object types, see the Remarks for the EventProvider class.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 3.5, 4.0, 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

WriteEvent(EventDescriptor, String)

Writes an event. The event data is specified as a string.

C#
[System.Security.SecurityCritical]
public bool WriteEvent(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, string data);

Parameters

eventDescriptor
EventDescriptor

An instance of EventDescriptor that identifies the event to write.

data
String

The string to write as the event data.

Returns

Is true if the event is written; otherwise, false. If false, call the GetLastWriteEventError() method to determine the cause of the failure.

Attributes

Exceptions

If data is null.

Examples

C#
private static Guid providerId = new Guid("{FB33FDA8-45FB-4df0-8A55-EEB4BA88E7E7}");  

EventProvider provider = new EventProvider(providerId);  
EventDescriptor writeEvent;  

if (provider.IsEnabled())  
{  
     unchecked  
     {  
          writeEvent = new EventDescriptor(0x2, 0x0, 0x10, 0x3, 0x0, 0x0, (long)0x8000000000000006);  
     }  

     if (!provider.WriteEvent(ref writeEvent, "Write event."))  
          Console.WriteLine(EventProvider.GetLastWriteEventError());  
}  

provider.Close();  

Remarks

If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.

The maximum string length is limited to 64 KB minus the size of the event headers. The event size is less if the session's buffer size is less and the session includes extended data items with the event.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 3.5, 4.0, 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

WriteEvent(EventDescriptor, Int32, IntPtr)

Writes an event. The event data is specified as a block of memory.

C#
[System.Security.SecurityCritical]
protected bool WriteEvent(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, int dataCount, IntPtr data);

Parameters

eventDescriptor
EventDescriptor

An instance of EventDescriptor that identifies the event to write.

dataCount
Int32

Size of the event data to which the data parameter points. The maximum event data size is limited to 64 KB minus the size of the event headers. The event size is less if the session's buffer size is less and the session includes extended data items with the event.

data
IntPtr

Pointer to the event data to write.

Returns

Is true if the event is written; otherwise, false. If false, call the GetLastWriteEventError() method to determine the cause of the failure.

Attributes

Remarks

If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 3.5, 4.0, 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