EventLog.EntryWritten Event
Assembly: System (in system.dll)
'Declaration Public Event EntryWritten As EntryWrittenEventHandler 'Usage 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) signal.WaitOne() End Sub ' Main Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs) signal.Set() 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.set_Log("MyCustomLog");
myNewLog.add_EntryWritten(new EntryWrittenEventHandler(
MyOnEntryWritten));
myNewLog.set_EnableRaisingEvents(true);
signal = new AutoResetEvent(false);
signal.WaitOne();
} //main
private static void MyOnEntryWritten(Object source,
EntryWrittenEventArgs e)
{
signal.Set();
} //MyOnEntryWritten
} //MySample
- EventLogPermission for administering event log information on the computer. Associated enumeration: EventLogPermissionAccess.Administer
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.