EventSource.WriteEvent Method (Int32, String)

.NET Framework (current version)

Writes an event by using the provided event identifier and string argument.

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

Protected Sub WriteEvent (
	eventId As Integer,
	arg1 As String


Type: System.Int32

The event identifier. This value should be between 0 and 65535.

Type: System.String

A string argument.

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.

When you implement a method that is identified as an ETW event in an EventSource-derived class. You must call the base class WriteEvent method passing the EventId and the same arguments as the implemented method similar to the following example.

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
 base.WriteEvent(2, arg1);

The following example shows how to use this method overload to write an event. This code example is part of a larger example provided for the EventSource class.

<[Event](1, Message:="Application Failure: {0}", Level:=EventLevel.Error, Keywords:=Keywords.Diagnostic)> _
Public Sub Failure(ByVal message As String)
    WriteEvent(1, message)
End Sub 'Failure

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top