You can create event handlers for your EventLog components that automatically call the EntryWritten procedure when an entry is written to a log. An event handler is a method that is bound to an event for a component, form, or control. Each event handler provides two parameters that allow you to handle the event properly — the sender, which provides an object reference to the object responsible for the event, and the e parameter, which provides an object for representing the event and its information.
For more information on event handlers, see Event Handling.
To create your own handler
[Visual Basic]
[C#]
EventLog eventLog1 = new EventLog();
eventLog1.Log = “myLog”;
eventLog1.MachineName = “myMachine”;
eventLog1.AddOnEntryWritten(new EventLogEventHandler(OnEntryWritten));
eventLog1.Monitoring = true;
public static void OnEntryWritten(Object source, EventLogEvent e){
Console.WriteLine("Written: " + e.Entry.Message);
}
Note For more information on this syntax, see Event Handling.