EventSource.WriteEventCore Method

.NET Framework 4.5

Creates a new WriteEvent overload by using the provided event identifier and event data.

This API is not CLS-compliant. 

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

protected void WriteEventCore(
	int eventId,
	int eventDataCount,
	EventSource.EventData* data


Type: System.Int32

The event identifier.

Type: System.Int32

The number of event data items.

Type: System.Diagnostics.Tracing.EventSource.EventData*

The structure that contains the event data.

eventid should be greater than 0 or less than 65535 or errors can occur in the operation. If errors do occur, you can get more information about the source of the error by checking the output stream of the debugger, if you have a debugger attached to the process firing events. You can also look for errors reported in the ETW event stream, if you have an ETW listener on the event source where the error occurs.

This protected method enables users to define new WriteEvent overloads that are faster than the provided overloads. Creating a new overload involves unsafe code. The basic procedure is to stack-allocate an array of event data descriptors that matches the number of payload items. For each payload item, set the correct size and value in the event data array.Call WriteEventCore with the initialized array.

The following example shows how to add a WriteEvent overload that accepts four integer arguments.

        public unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3, int arg4) {
            EventData* dataDesc = stackalloc EventProvider.EventData[4];

            dataDesc[0].DataPointer = (IntPtr)(&arg1);
            dataDesc[0].Size = 4;
            dataDesc[1].DataPointer = (IntPtr)(&arg2);
            dataDesc[1].Size = 4;
            dataDesc[2].DataPointer = (IntPtr)(&arg3);
            dataDesc[2].Size = 4;
            dataDesc[3].DataPointer = (IntPtr)(&arg4);
            dataDesc[3].Size = 4;

            WriteEventCore(eventId, 4, (IntPtr)dataDesc);

.NET Framework

Supported in: 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft