Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

EventLog.WriteEntry Method

Writes an entry in the event log.

Overload List

Writes an information type entry, with the given message text, to the event log.

[Visual Basic] Overloads Public Sub WriteEntry(String)
[C#] public void WriteEntry(string);
[C++] public: void WriteEntry(String*);
[JScript] public function WriteEntry(String);

Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log.

[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);

Writes an information type entry with the given message text to the event log, using the specified registered event source.

[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);

Writes an entry with the given message text and application-defined event identifier to the event log.

[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer)
[C#] public void WriteEntry(string, EventLogEntryType, int);
[C++] public: void WriteEntry(String*, EventLogEntryType, int);
[JScript] public function WriteEntry(String, EventLogEntryType, int);

Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log, using the specified registered event source.

[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);

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log.

[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer, Short)
[C#] public void WriteEntry(string, EventLogEntryType, int, short);
[C++] public: void WriteEntry(String*, EventLogEntryType, int, short);
[JScript] public function WriteEntry(String, EventLogEntryType, int, Int16);

Writes an entry with the given message text and application-defined event identifier to the event log, using the specified registered event source.

[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType, Integer)
[C#] public static void WriteEntry(string, string, EventLogEntryType, int);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, int);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, int);

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, and appends binary data to the message.

[Visual Basic] Overloads Public Sub WriteEntry(String, EventLogEntryType, Integer, Short, Byte())
[C#] public void WriteEntry(string, EventLogEntryType, int, short, byte[]);
[C++] public: void WriteEntry(String*, EventLogEntryType, int, short, unsigned char __gc[]);
[JScript] public function WriteEntry(String, EventLogEntryType, int, Int16, Byte[]);

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(String, String, EventLogEntryType, Integer, Short)
[C#] public static void WriteEntry(string, string, EventLogEntryType, int, short);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, int, short);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, int, Int16);

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) and appends binary data to the message.

[Visual Basic] Overloads Public Shared Sub WriteEntry(String, String, EventLogEntryType, Integer, Short, Byte())
[C#] public static void WriteEntry(string, string, EventLogEntryType, int, short, byte[]);
[C++] public: static void WriteEntry(String*, String*, EventLogEntryType, int, short, unsigned char __gc[]);
[JScript] public static function WriteEntry(String, String, EventLogEntryType, int, Int16, Byte[]);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of WriteEntry. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim myByte(9) As Byte
Dim i As Integer
For i = 0 To 9
   myByte(i) = CByte(i Mod 2)
Next i
' Write an informational entry to the event log.
Console.WriteLine("Write from second source ")
EventLog.WriteEntry("SecondSource", "Writing warning to event log.", _
                     EventLogEntryType.Error, myEventID , myCategory , myByte)

[C#] 
byte[] myByte=new byte[10];
for(int i=0;i<10;i++)
{
   myByte[i]= (byte)(i % 2);
}
// Write an informational entry to the event log.
Console.WriteLine("Write from second source ");
EventLog.WriteEntry("SecondSource","Writing warning to event log.", 
                     EventLogEntryType.Error,myEventID ,myCategory ,myByte);        

[C++] 
Byte myByte[] = new Byte[10];
for (int i=0; i<10; i++) {
    myByte[i] = (Byte)(i % 2);
}
// Write an informational entry to the event log.
Console::WriteLine(S"Write from second source ");
EventLog::WriteEntry(S"SecondSource",S"Writing warning to event log.",
    EventLogEntryType::Error, myEventID, myCategory, myByte);

[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.

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace

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