This documentation is archived and is not being maintained.

EventLog.WriteEntry Method (String, String, EventLogEntryType, Int32, Int16)

.NET Framework 1.1

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, using the specified registered event source. The category can be used by the event viewer to filter events in the log.

[Visual Basic]
Overloads Public Shared Sub WriteEntry( _
   ByVal source As String, _
   ByVal message As String, _
   ByVal type As EventLogEntryType, _
   ByVal eventID As Integer, _
   ByVal category As Short _
)
[C#]
public static void WriteEntry(
 string source,
 string message,
 EventLogEntryType type,
 int eventID,
 short category
);
[C++]
public: static void WriteEntry(
 String* source,
 String* message,
 EventLogEntryType type,
 int eventID,
 short category
);
[JScript]
public static function WriteEntry(
   source : String,
 message : String,
 type : EventLogEntryType,
 eventID : int,
 category : Int16
);

Parameters

source
The source by which the application is registered on the specified computer.
message
The string to write to the event log.
type
One of the EventLogEntryType values.
eventID
The application-specific identifier for the event.
category
The application-specific subcategory associated with the message.

Remarks

Use this method to write an entry with an application-defined category to the event log, using a source that is already registered as an event source for the appropriate log. The Event Viewer can use the category to filter events in the log. Each application can define its own numbered categories and the text strings to which they map. The categories must be numbered consecutively beginning with the number 1. The Event Viewer presents the category to the user in the Category column.

In addition to the category, you can specify an event identifier for the event being written to the event log. Event identifiers, along with the event source, uniquely identify an event. Each application can define its own numbered events and the description strings to which they map. Event viewers display these string values in the Event column. They areintended to help the user understand what went wrong and suggest what actions to take.

Finally, you can specify an EventLogEntryType for the event being written to the event log. The type is indicated in the Event Viewer for a log by an icon and text in the Type column. This indicates whether the event type is error, warning, information, success audit, or failure audit.

WriteEntry lets you specify a string message to write to the log. This method writes the given string directly to the log; it does not use a localizable message file.

Note   If you write an entry to a remote computer, the value of the message (the text string) might not be what you expect if the remote computer is not running the .NET Framework.

Example

[Visual Basic] 
Dim myEventID as Integer = 10
Dim myCategory as Short=20
' Write an informational entry to the event log.
Console.WriteLine("Write from first source ")
EventLog.WriteEntry("FirstSource", "Writing warning to event log.",  _
                           EventLogEntryType.Information, myEventID , myCategory )

[C#] 
int  myEventID = 20;
short myCategory = 10; 
// Write an informational entry to the event log.
Console.WriteLine("Write from first source ");
EventLog.WriteEntry("FirstSource","Writing warning to event log.",
                     EventLogEntryType.Information,myEventID ,myCategory );

[C++] 
int  myEventID = 20;
short myCategory = 10;
// Write an informational entry to the event log.
Console::WriteLine(S"Write from first source ");
EventLog::WriteEntry(S"FirstSource",S"Writing warning to event log.",
    EventLogEntryType::Information,myEventID, myCategory);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.WriteEntry Overload List | EventLogEntryType | Source | CreateEventSource | DeleteEventSource | SourceExists | Entries

Show: