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.

public:
 bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, ... cli::array <System::Object ^> ^ eventPayload);
[System.Security.SecurityCritical]
public bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, params object[] eventPayload);
member this.WriteEvent : EventDescriptor * obj[] -> bool
Public Function WriteEvent (ByRef eventDescriptor As EventDescriptor, ParamArray eventPayload As Object()) As Boolean

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

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.

WriteEvent(EventDescriptor, String)

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

public:
 bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, System::String ^ data);
[System.Security.SecurityCritical]
public bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, string data);
member this.WriteEvent : EventDescriptor * string -> bool
Public Function WriteEvent (ByRef eventDescriptor As EventDescriptor, data As String) As Boolean

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

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.

WriteEvent(EventDescriptor, Int32, IntPtr)

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

protected:
 bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, int dataCount, IntPtr data);
[System.Security.SecurityCritical]
protected bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, int dataCount, IntPtr data);
member this.WriteEvent : EventDescriptor * int * nativeint -> bool
Protected Function WriteEvent (ByRef eventDescriptor As EventDescriptor, dataCount As Integer, data As IntPtr) As Boolean

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