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.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

Public Event EntryWritten As EntryWrittenEventHandler
Dim instance As EventLog
Dim handler As EntryWrittenEventHandler

AddHandler instance.EntryWritten, handler

/** @event */
public void add_EntryWritten (EntryWrittenEventHandler value)

/** @event */
public void remove_EntryWritten (EntryWrittenEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

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.

The following example handles an entry written event.

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 

import System.*;
import System.Diagnostics.*;
import System.Threading.*;

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

    public static void main(String[] args)
        EventLog myNewLog = new EventLog();

        myNewLog.add_EntryWritten(new EntryWrittenEventHandler(
        signal = new AutoResetEvent(false);
    } //main

    private static void MyOnEntryWritten(Object source, 
        EntryWrittenEventArgs e)
    } //MyOnEntryWritten
} //MySample

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0