Use this method to write an information entry to the event log associated with this EventLog instance. If you want to specify any other EventLogEntryType, use a different overload of WriteEntry.
You must set the Source property on your EventLog component before you can write entries to the log. 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.
If the source specified in the Source property of this EventLog instance is not registered on the computer that your component is writing to, WriteEntry calls CreateEventSource and registers the source.
Note |
|---|
| If you do not specify a MachineName for your EventLog instance before you call CreateEventSource or WriteEntry, the local computer (".") is assumed. |
If the system needs to register the Source through a call to WriteEntry and the Log property has not been set on your EventLog instance, the log defaults to the Application log.
Note |
|---|
| Many of the exceptions listed above are generated by errors raised during the process of registering the Source. |
The source must be configured either for writing localized entries or for writing direct strings. The WriteEntry method writes the given string directly to the event log; it does not use a localizable message resource file. Use the WriteEvent 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 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.
Note |
|---|
| If you write an entry to a remote computer, the value of the message (the text string) might not be what you expect if the remote computer is not running the .NET Framework. |
Note |
|---|
| If the message parameter contains a NUL character, the message in the event log is terminated at the NUL character. |