System 2.0.0.0 4.0.0.0 System.Object

Use the class to configure a new source for writing localized entries to an event log. It is not necessary to use this class to read from an event log.

This class defines the configuration settings for a new event source and its associated event log. The associated event log can be on the local computer or a remote computer. To create a new source for a new or existing event log on the local computer, set the and properties of an and call the method. This method creates the event source you specify in the property and registers it for the event log specified in . This behavior is similar to using the class to register an event source for an event log.

Use the and methods to write events to an event log. You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.

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 , or using the method. You must have administrative rights on the computer to create a new event source.

You can create an event source for an existing event log or a new event log. When you create a new source for a new event log, the system registers the source for that log, but the log is not created until the first entry is written to it.

Each source can only write to one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might need multiple sources configured for different event logs or different resource files.

To change the configuration details of an existing source, you must delete the source and then create it with the new configuration. If other applications or components use the existing source, create a new source with the updated configuration rather than deleting the existing source.

You can register the event source with localized resources for your event category and message strings. Your application can write event log entries using resource identifiers, rather than specifying the actual string. The Event Viewer uses the resource identifier to find and display the corresponding string from the localized resource file based on current language settings. You can register a separate file for event categories, messages, and parameter insertion strings, or you can register the same resource file for all three types of strings. Use the , , , and properties to configure the source to write localized entries to the event log. If your application writes string values directly to the event log, you do not need to set these properties.

The source must be configured either for writing localized entries or for writing direct strings. The method writes the given string directly to the event log; it does not use a localizable message resource file. Use the method to write events using a localized message resource file.

If your application writes entries using both resource identifiers and string values, you must register two separate sources. For example, configure one source with resource files, and then use that source in the method to write entries using resource identifiers to the event log. Then create a different source without resource files and use that source in the method to write strings directly to the event log using that source.

Represents the configuration settings used to create an event log source on the local computer or a remote computer.

- Constructor
  2.0.0.0
  4.0.0.0

  To write entries to an event log, you must first create an event source for the event log. To register a new source, initialize an instance, configure the instance properties for your application, and call the method. After the source is registered, you can write entries from the source using the or methods.

  You can register the event source with localized resources for your event category and message strings. Your application can write event log entries using resource identifiers, rather than specifying the actual string. The Event Viewer uses the resource identifier to find and display the corresponding string from the localized resource file based on current language settings. You can register a separate file for event categories, messages, and parameter insertion strings, or you can register the same resource file for all three types of strings. Use the , , , and properties to configure the source to write localized entries to the event log. If your application writes string values directly to the event log, you do not need to set these properties.

  The source must be configured either for writing localized entries or for writing direct strings. If your application writes entries using both resource identifiers and string values, you must register two separate sources. For example, configure one source with resource files, and then use that source in the method to write entries using resource identifiers to the event log. Then create a different source without resource files and use that source in the method to write strings directly to the event log.

  The following table shows initial property values for an .

  Property

  Initial Value

  The parameter.

  The parameter.

  The local computer (".").

  Zero

  null (Nothing in Visual Basic).

  null (Nothing in Visual Basic).

  null (Nothing in Visual Basic).

  Initializes a new instance of the class with a specified event source and event log name.

  The name to register with the event log as a source of entries.
  The name of the log to which entries from the source are written.
- Property
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  Use the and properties to write events with localized category strings. The Event Viewer displays the category for an event entry if you supply a category when you write the event. Event log categories are application-defined strings that help filter events, or provide further information on the event. For example, your application can define separate categories for different components or different operations.

  Event categories are optional; if your application does not use categories, do not set the and properties.

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

  Gets or sets the number of categories in the category resource file.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  Use the and properties to write events with localized category strings. The Event Viewer displays the category for an event entry if you supply a category when you write the event. Event log categories are application-defined strings that help filter events, or provide further information on the event. For example, your application can define separate categories for different components or different operations.

  Event categories are optional; if your application does not use categories, do not set the and properties.

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

  Gets or sets the path of the resource file that contains category strings for the source.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  Use the property to identify the event log that your application writes entries to using the new source. The event log can be a new log or an existing log. Applications and services should write to the Application log or a custom log. Device drivers should write to the System log. If you do not explicitly set the property, the event log defaults to the Application log.

  The Security log is read-only.

  To target an existing log for the new source, set the property to the existing event log name. To create a new event log for the source, you must set the property. Event log names must consist of printable characters, and cannot include the characters '*', '?', or '\'. The first 8 characters of the event log name must be different from the first 8 characters of existing names of event logs on the specified computer.

  The operating system stores event logs as files. When you use or the method to create a new event log, the associated file is stored in the %SystemRoot%\System32\Config directory on the specified computer. The file name is set by appending the first 8 characters of the property with the ".evt" file name extension.

  Gets or sets the name of the event log to which the source writes entries.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  The value cannot be an empty string. If the machine name is not explicitly set, it defaults to the local computer (".").

  When registering a source on a remote computer, you must have administrative rights on that computer to write the registry values with sufficient permissions.

  Gets or sets the name of the computer on which to register the event source.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  Use the property to configure an event log source to write localized event messages. Event messages are application-defined strings that describe the event to the user.

  Your application can write event log entries using resource identifiers. A resource identifier indexes a message located in the . The Event Viewer uses the resource identifier to find and display the corresponding string from the localized message resource file based on current language settings.

  The event source must be configured either for writing localized entries or for writing direct strings. Use the method to write localized entries for a source configured with a message resource file.

  If your application writes event message strings directly, rather than using a resource identifier in a localized resource file, do not set the property.

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

  Gets or sets the path of the message resource file that contains message formatting strings for the source.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  Use the property to configure an event log source to write localized event messages with inserted parameter strings. Each localized event message specified in the property can contain placeholders for insertion strings. These placeholders are used to specify the position and resource identifier for a language-independent string within the event message. The Event Viewer fills in the placeholders using the corresponding strings from the and formats the event log message for the localized event entry.

  For example, the following section of a message text file defines a string with a parameter placeholder:

  `MessageId = 1501 Severity = Success Facility = Application SymbolicName = COMPONENT_STARTING Language=English Component %%6050 is starting. .`

  Within the parameter resource file, the insertion string must be defined with the resource identifier that corresponds to the placeholder, as shown below:

  `MessageId = 6050 Severity = Success Facility = Application SymbolicName = COMPONENT_NAME_MSGID Language=English TRIGGER.EXE .`

  The event source must be configured either for writing localized entries or for writing direct strings. Use the method to write localized entries for a source configured with a message resource file.

  If your application writes event message strings directly to the event log, or if your property does not contain messages with parameter insertion placeholders, do not set the property.

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

  Gets or sets the path of the resource file that contains message parameter strings for the source.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  The source name is often the name of the application, or the name of a component within a large application. The method uses the , , and properties to create registry values on the target computer for the new source and its associated event log. A new source name cannot match an existing source name or an existing event log name on the target computer.

  After the registry values for the source are created, your application can use the source to write entries to the configured event log.

  Each source can only write to one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might require multiple sources configured for different event logs or different resource files.

  Gets or sets the name to register with the event log as an event source.