There are several properties involved in creating an instance of the EventLog component:
Note You can set the Log property on your component directly, or you can set it in code that registers your component as an event source. After registering the component as a source, a connection is already set in the server's registry linking your component to a specific log.
[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
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.
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.
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