Export (0) Print
Expand All

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 EntryWrittenEventHandler EntryWritten
/** @event */
public void add_EntryWritten (EntryWrittenEventHandler value)

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

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

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 six seconds previously. This implies you will only receive one EntryWritten event notification within a six-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, you are less likely to miss an event. However, if write events occur more frequently, you might not recieve the event notification until the next interval. Typically, missed event notifications are not lost, but delayed.

The following example handles an entry written event.

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);
	signal.WaitOne();        

    }       

    public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){
        signal.Set();
    }
}
   

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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft