You can define an OnEntryWritten event handler for an instance of an EventLog component. If you add an EventLog component from the Component tab of the toolbox, you can double-click the EventLog component (shown in the component tray in Figure 20.7) to generate the event. An example of an OnEntryWritten event handler is shown next .
Figure 20.7. Nonvisual components like the EventLog component are managed in the component tray.
Private Sub EventLog1_EntryWritten(ByVal sender As System.Object, _ ByVal e As System.Diagnostics.EntryWrittenEventArgs) _ Handles EventLog1.EntryWritten MsgBox("Log Written") End Sub
The OnEntryWritten event is an EntryWrittenEventHandler delegate. The first argument is an Object argument, which if invoked by the EventLog, is an EventLog object. The second argument is an EntryWrittenEventArgs object. A significant property of the e parameter is an EventLogEntry, Entry. The Entry property allows you to evaluate entry objects as they are being added.
Unlike many events, the OnEntryWritten event isn't raised automatically. You must set the EnableRaisingEvents property to True before your application will receive entry event notification. EnableRaisingEvents is a dynamic property that can be set from the Dynamic Properties dialog box (see Figure 20.8) or by using an external configuration file.
Figure 20.8. Check the EnableRaising Properties value in the Dynamic Properties dialog box.
Dynamic configuration files can be used to manage dynamic properties with XML in a .config file. You can use .config files to manage the state of properties without rebuilding your applications. For example, the configuration file can be used to turn entry events on or off externally.