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!

Configuring EventLog Components

There are several properties involved in creating an instance of the EventLog component:

[Visual Basic]

EventLog.CreateEventSource("mysource","mylog","myserver")
Dim el As New EventLog
el.Source = "mysource"
el.MachineName = "myserver"
el.WriteEntry "Test"
[C#]
EventLog.CreateEventSource("mysource","mylog","myserver");
EventLog el = new EventLog();
el.Source = "mysource";
el.MachineName = "myserver";
el.WriteEntry("Test");
Note If you just want to read entries, you can set just the Log and MachineName properties.

For more information on these properties, see Event Log References.

Note Once you have set the Log property, you may have to reboot the server before the system will recognize a change to the selected log. For example, if you set the component to reference the Application log, then later change it to reference the System log, you may need to reboot before the new value will be recognized.

The entries you retrieve from an event log are categorized by multiple properties. For information on these properties, see EventLogEntry Members.

To configure an instance of the EventLog component

  1. Create an instance of the EventLog component. For details, see Creating EventLog Components .
  2. Set the following values:
    • Set the Log property to Application, Security, System, or the name of a custom log with which you want your component to interact.
      Note   When you are referencing a log in an international application, you can query the DisplayName property to retrieve the localized name of the log. You must set the Log property to the non-localized (usually in English) version of the log name.
    • Set the MachineName property to the name of the server on which the event log that you want to write to exists, or use a period (.) to indicate the local machine.
  3. If you will be writing to the event log, set the Source property to the string of your choice. You do not have to set the Source property if you only want to read an existing log.
    Note   The string you enter in the Source property is used to register your component as a valid source of entries to the event log with which your component interacts. If the source has already been registered, the Log property will automatically be set to the log in which the source is registered. If it has not, the Log property will default to Application.
    The actual registry occurs when you either call CreateEventSource in your code, or when the first WriteEntry procedure occurs. For more information on event sources, see Adding Your Application as a Source of Event Log Entries.
  4. Set the component instance’s Monitoring property to true.

See Also

Event Log Entry Properties | Event Log References | Creating EventLog Components  | Adding Your Application as a Source of Event Log Entries | Writing Entries to Event Logs