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)

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.

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

Community Additions

ADD
Show:
© 2014 Microsoft