NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Handling the EntryWritten Event

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

  1. Create an instance of the EventLog component. For details, see Creating EventLog Components .
  2. Set the necessary properties for the component. For details, see Configuring EventLog Components.
  3. Use the AddOnEntryWritten method to create an event handling delegate for your component that will call the EventLog1_EntryWritten procedure when an entry is written to the log. Your code should look like this:
    [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.
  4. Create the EntryWritten procedure and define the code you want to process the entries.
    
    

See Also

Event Handling