Export (0) Print
Expand All

EventLog.WriteEntry Method (String, String)

.NET Framework 1.1

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


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


Use this method to write an information entry to the event log, using a source that is already registered as an event source for the appropriate log. If you want to specify any other EventLogEntryType, use a different overload of WriteEntry.

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 an entry to an event log, "MyNewLog", on the local computer, and creates the source "MySource" if the source does not exist.

[Visual Basic, C#, C++] Note   The code in this example that creates the event source is not necessary. If the source you set in the Source property does not exist, the WriteEntry method creates it before writing to the event log.
[Visual Basic] 
Option Strict
Option Explicit

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        ' Create the source, if it does not already exist.
        If Not EventLog.SourceExists("MySource") Then
            EventLog.CreateEventSource("MySource", "myNewLog")
        End If
        ' Write an informational entry to the event log.    
        EventLog.WriteEntry("MySource", "Writing to event log.")
    End Sub ' Main 
End Class ' MySample 

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

    public static void Main(){
        // Create the source, if it does not already exist.
            EventLog.CreateEventSource("MySource", "myNewLog");
        // Write an informational entry to the event log.    
        EventLog.WriteEntry("MySource", "Writing to event log.");

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

int main(){

    // Create the source, if it does not already exist.
        EventLog::CreateEventSource(S"MySource", S"myNewLog");

    // Write an informational entry to the event log.    
    EventLog::WriteEntry(S"MySource", S"Writing 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 | Source | CreateEventSource | DeleteEventSource | SourceExists | Entries

© 2014 Microsoft