This documentation is archived and is not being maintained.

EventLog.EntryWritten Event

Occurs when an entry is written to an event log on the local computer.

[Visual Basic]
Public Event EntryWritten As EntryWrittenEventHandler
public event EntryWrittenEventHandler EntryWritten;
public: __event EntryWrittenEventHandler* EntryWritten;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EntryWrittenEventArgs containing data related to this event. The following EntryWrittenEventArgs property provides information specific to this event.

Property Description
Entry Gets the event log entry that was written to the log.


To get event notifications, you must set EnableRaisingEvents to true. You can only receive event notifications when entries are written on the local computer. You cannot receive notifications for entries written on remote computers.

When you create an EntryWritten delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate. For more information about handling events with delegates, see Consuming Events.

The system responds to WriteEntry only if the last write event occurred at least five seconds previously. This implies you will only receive one EntryWritten event notification within a five-second interval, even if more than one event log change occurs. If you insert a sufficiently long sleep interval (around 10 seconds) between calls to WriteEntry, no events will be lost. However, if write events occur more frequently, the most recent write events could be lost.


[Visual Basic, C#, C++] The following example handles an entry written event.

[Visual Basic] 
Option Explicit On 
Option Strict On

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample

    ' This member is used to wait for events.
    Private Shared signal As AutoResetEvent

    Public Shared Sub Main()

        Dim myNewLog As New EventLog()
        myNewLog.Log = "MyCustomLog"

        AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
        myNewLog.EnableRaisingEvents = True

        signal = New AutoResetEvent(False)
    End Sub ' Main

    Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
    End Sub ' MyOnEntryWritten
End Class ' MySample 

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

    // This member is used to wait for events.
    static AutoResetEvent signal;

    public static void Main(){
        EventLog myNewLog = new EventLog();
        myNewLog.Log = "MyCustomLog";                      
        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;
    signal = new AutoResetEvent(false);


    public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){

#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
__gc class MySample{

    // This member is used to wait for events.
    static AutoResetEvent* signal;

    static void main(){
        EventLog* myNewLog = new EventLog();
        myNewLog->Log = S"MyCustomLog";                      
        myNewLog->EntryWritten += new EntryWrittenEventHandler(0, MyOnEntryWritten);
        myNewLog->EnableRaisingEvents = true;
    signal = new AutoResetEvent(false);


    static void MyOnEntryWritten(Object* /*source*/, EntryWrittenEventArgs* /*e*/){

int main()

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