Gets or sets the source name to register and use when writing to the event log.
Assembly: System (in System.dll)
<TypeConverterAttribute("System.Diagnostics.Design.StringValueConverter, System.Design, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> <SettingsBindableAttribute(True)> Public Property Source As String
Property ValueType: System.String
The name registered with the event log as a source of entries. The default is an empty string ("").
The source name results in a registry key path longer than 254 characters.
The event source indicates what logs the event. It is often the name of the application, or the name of a subcomponent of the application, if the application is large. Applications and services should write to the Application log or a custom log. Device drivers should write to the System log.
You only need to specify an event source if you are writing to an event log. Before writing an entry to an event log, you must register the event source with the event log as a valid source of events. When you write a log entry, the system uses the Log and MachineName.property to find the appropriate log in which to place your entry. If you are reading the event log, you can either specify the , or a
Use WriteEvent and WriteEntry 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 configuration. 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 EventLogInstaller, or using the CreateEventSource 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.
The source must be unique on the local computer; a new source name cannot match an existing source name or an existing event log name. Each source can write to only 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.
If you change the EventLog to which it is registered is closed and all event handles are released.value, the
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 WriteEvent 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 WriteEntry method to write strings directly to the event log using that source.
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.
If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.
The following example creates the source MySource if it does not already exist, and writes an entry to the event log MyNewLog.
Option Explicit Option Strict Imports System Imports System.Diagnostics Imports System.Threading Class MySample Public Shared Sub Main() ' Create the source, if it does not already exist. If Not EventLog.SourceExists("MySource") Then EventLog.CreateEventSource("MySource", "MyNewLog") Console.WriteLine("CreatingEventSource") End If ' Create an EventLog instance and assign its source. Dim myLog As New EventLog() myLog.Source = "MySource" ' Write an informational entry to the event log. myLog.WriteEntry("Writing to event log.") Console.WriteLine("Message written to event log.") End Sub ' Main End Class ' MySample
Available since 1.1