System.Diagnostics.EventInstance Class

Represents language-neutral information for an event log entry.

See Also: EventInstance Members

Syntax

public class EventInstance

Remarks

Use System.Diagnostics.EventInstance to write an event log entry with a resource identifier rather than a string value. To write an event log entry, initialize the EventInstance.InstanceId property and pass the instance to the erload:System.Diagnostics.EventLog.WriteEvent method. The Event Viewer uses the instance identifier to find and display the corresponding string from the localized resource file based on current language settings. You must register the event source with the corresponding resource file before you write events using resource identifiers.

When writing events, you can set the EventInstance.EntryType property to specify the icon that the Event Viewer displays for the entry. You can also specify a EventInstance.CategoryId property to specify the category that the Event Viewer displays for the entry.

The Event Viewer uses the category to filter events written by an event source. The Event Viewer can display the category as a numeric value, or it can use the category as a resource identifier to display a localized category string.

To display localized category strings in the Event Viewer, you must use an event source configured with a category resource file, and set the EventInstance.CategoryId to a resource identifier in the category resource file. If the event source does not have a configured category resource file, or the specified EventInstance.CategoryId does not index a string in the category resource file, and then the Event Viewer displays the numeric category value for that entry. Configure the category resource file, along with the number of category strings in the resource file, using the System.Diagnostics.EventLogInstaller or the System.Diagnostics.EventSourceCreationData class.

You must register a source for an event log before using System.Diagnostics.EventInstance to write an event with the erload:System.Diagnostics.EventLog.WriteEvent method. The source must be configured for writing localized entries to the log and the source must define at least a message resource file.

Create the new event source during the installation of your application. This allows time for the operating system to refresh its list of registered event sources and their configurations. If the operating system has not refreshed its list of event sources, and you attempt to write an event with the new source, the write operation will fail. You can configure a new source using an System.Diagnostics.EventLogInstaller, or using the erload:System.Diagnostics.EventLog.CreateEventSource method. You must have administrative rights on the computer to create a new event source.

For details about defining event messages and building event log resource files, see the "Message Compiler" topic in the Platform SDK documentation at tp://msdn.microsoft.com.

Requirements

Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0