Logs an entry in the event log.
[To be supplied.]
[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType, Integer, Integer)
[C#] public static void WriteEntry(String, String, EventLogEntryType, short, short);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, short, short);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, Int16, Int16);
Writes an entry of the specified type with the user-defined eventID and category to the event log. The category can be used by the event viewer to filter events in the log.
[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer, Integer)
[C#] public void WriteEntry(String, EventLogEntryType, short, short);
[C++] public: void WriteEntry(String*, EventLogEntryType, short, short);
[JScript] public function WriteEntry(String, EventLogEntryType, Int16, Int16);
Writes an entry of the specified type with the user-defined eventID and category to the event log, and appends binary data to the message. The Event Viewer does not interpret this data; it displays raw data only in a combined hexadecimal and text format.
[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer, Integer, Byte())
[C#] public void WriteEntry(String, EventLogEntryType, short, short, byte[]);
[C++] public: void WriteEntry(String*, EventLogEntryType, short, short, unsigned char[]);
[JScript] public function WriteEntry(String, EventLogEntryType, Int16, Int16, Byte[]);
Writes an information type entry with the given message text to the event log.
[Visual Basic] Overloads Overridable Public Sub WriteEntry(String)
[C#] public virtual void WriteEntry(String);
[C++] public: virtual void WriteEntry(String*);
[JScript] public function WriteEntry(String);
[To be supplied.]
[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType, Integer, Integer, Byte())
[C#] public static void WriteEntry(String, String, EventLogEntryType, short, short, byte[]);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, short, short, unsigned char[]);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, Int16, Int16, Byte[]);
Writes an entry of the specified EventLogEntryType to the event log. Valid types are Error, Warning, Information, Success Audit, and Failure Audit.
[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType)
[C#] public void WriteEntry(String, EventLogEntryType);
[C++] public: void WriteEntry(String*, EventLogEntryType);
[JScript] public function WriteEntry(String, EventLogEntryType);
[To be supplied.]
[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String)
[C#] public static void WriteEntry(String, String);
[C++] public: static void WriteEntry(String*, String*);
[JScript] public static function WriteEntry(String, String);
[To be supplied.]
[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType)
[C#] public static void WriteEntry(String, String, EventLogEntryType);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType);
[JScript] public static function WriteEntry(String, String, EventLogEntryType);
[To be supplied.]
[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType, Integer)
[C#] public static void WriteEntry(String, String, EventLogEntryType, short);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, short);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, Int16);
Writes an entry of the specified EventLogEntryType and with the user-defined eventID to the event log.
[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer)
[C#] public void WriteEntry(String, EventLogEntryType, short);
[C++] public: void WriteEntry(String*, EventLogEntryType, short);
[JScript] public function WriteEntry(String, EventLogEntryType, Int16);
The following example connects to a log with the source "myNewSource". It then writes an entry to the log. This example assumes there is an existing source named "myNewSource" on the local computer.
The procedure defines its own eventId values, which correspond to what appears in the Event column of the Event Viewer. The following table describes how the application-defined fileEventType strings correspond to locally-defined eventId values. Note that these are randomly selected for this example; there is no inherent meaning in the eventId or fileEventType values that were chosen.
File Event String | eventId Value |
---|---|
OpenFile | 0x01 |
ModifyFile | 0x02 |
CloseFile | 0x04 |
CreateFile | 0x08 |
DeleteFile | 0x10 |
FileAccessDenied | 0x20 |
FileError | 0x40 |
When the entry is written to the event log, the entry type (Information, Failure Audit) is specified as well. You can view the entry information in the Event Viewer to see the Type (type), Event (eventId), and message text.
Import the System.Diagnostics namespace for this example.
Note This example shows how to use one of the overloaded versions of WriteEntry. For other examples that may be available, see the individual overload topics.
[Visual Basic]
Private Sub WriteEntryWithId(ByVal fileEventType As String) 'Declare a new event log. Dim evtLog As EventLog 'The eventId corresponds to the file event. Dim eventId As Int16 'The EventLogEntryType we associate with the file event. Dim entryType As EventLogEntryType 'Instantiate a new event log. evtLog = New EventLog 'Connect the event log to the source passed in. evtLog.Source = "mySource" 'Set the eventId and entryType based on the file event passed in. Select Case fileEventType Case "OpenFile" 'This was randomly defined. The actual values are not crucial. eventId = 1 entryType = EventLogEntryType.SuccessAudit Case "ModifyFile" eventId = 2 entryType = EventLogEntryType.Information Case "CloseFile" eventId = 4 entryType = EventLogEntryType.Information Case "CreateFile" eventId = 8 entryType = EventLogEntryType.Information Case "DeleteFile" eventId = 16 entryType = EventLogEntryType.Information Case "FileAccessDenied" eventId = 32 entryType = EventLogEntryType.FailureAudit Case "FileError" eventId = 64 entryType = EventLogEntryType.Error End Select 'Write the entry information to the log. evtLog.WriteEntry("File access event occurred.", entryType, eventId) End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace