WriteEntry Method (String, String, EventLogEntryType)

EventLog.WriteEntry Method (String, String, EventLogEntryType)

.NET Framework 1.1

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( _
   ByVal source As String, _
   ByVal message As String, _
   ByVal type As EventLogEntryType _
public static void WriteEntry(
 string source,
 string message,
 EventLogEntryType type
public: static void WriteEntry(
 String* source,
 String* message,
 EventLogEntryType type
public static function WriteEntry(
   source : String,
 message : String,
 type : EventLogEntryType


The source by which the application is registered on the specified computer.
The string to write to the event log.
One of the EventLogEntryType values.


Use this method to write an entry of a specified EventLogEntryType to the event log, using a source already registered as an event source for the appropriate log. The type is indicated in the Event Viewer for a log by an icon and text in the Type column.

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.


[Visual Basic, C#, C++] The following example writes a warning entry to an event log, "MyNewLog", on the local computer.

[Visual Basic, C#, C++] Note    WriteEntry creates the source "MySource" if the source does not exist.
[Visual Basic] 
Option Explicit
Option Strict

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        ' Write an informational entry to the event log.    
        EventLog.WriteEntry("MySource", "Writing warning to event log.", _
    End Sub ' Main 
End Class ' MySample

using System;
using System.Diagnostics;
using System.Threading;
class MySample{

    public static void Main(){
        // Write an informational entry to the event log.    
            "Writing warning to event log.", 

#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;

int main(){

    // Write an informational entry to the event log.    
        S"Writing warning to event log.", 


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


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

© 2016 Microsoft