I would like to write to the default Application event log without creating an event log source automatically or through EventLog.CreateEventSource
. The program may be run as a non-administrator, who will have no way to create an event log source. This application has no installation program. Is there something that I can specify for the source that will "always work" in this case?
For reference, the error message was:
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.
You cannot write without registering event source and you need administrative rights to create one. If you have administrative rights and write a log without first creating source Windows creates the event source automatically.
From MSDN:
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.