Search code examples
windowsevent-log

Windows EventLog - Event ID 0


I have a windows service app that uses the EventLog for logging. In the app installer I run:

eventcreate /L APPLICATION /SO "My App" /T SUCCESS /id 1 /D "Initialised Log"

Then in my application logger in C# I do:

EventLog.WriteEntry(message, EventLogEntryType.Error, 1, 0, details);

However when I look in the Application EventLog, in addition to my events I see entries with EventID 0. I cannot use eventcreate to create an ID=0 entry (says ID must be >=1). So what is creating these events? and is there any way to stop eventlog from complaining about corrupted installations?

One example entry says:

The following information was included with the event:

Service started successfully.

the message resource is present but the message is not found in the string/message table


Solution

  • The ServiceBase class has a property AutoLog, which by default is true. This means that it will automatically report state changes like Start, Stop, Pause and Continue. MSDN documentation is here.

    If you want to report information to a custom log, rather than the Application log, or if you want to suppress these event log entries, you should set AutoLog to false in your constructor.