Henley Wing Chiu
Henley Wing Chiu

Reputation: 22535

Where can I find Window service event logs?

I am creating a Windows service, and am writing to the event log.

Here is how I create it:

if (!System.Diagnostics.EventLog.SourceExists("MySource"))
        {
            System.Diagnostics.EventLog.CreateEventSource(
                "MySource", "MyNewLog");
        }
        eventLog1.Source = "MySource";
        eventLog1.Log = "MyNewLog";

Here is how I write to the eventLog:

eventLog1.WriteEntry("In OnStart");

How can I find the file where this line is written? I tried to go to the Event Viewer but it only shows that the services stops and starts.

Upvotes: 1

Views: 11988

Answers (2)

Roy Dictus
Roy Dictus

Reputation: 33149

Your entry should show up in the Event Viewer (if the code runs under account with local Admin rights), but to answer your question, the event log files are stored in your

%SystemRoot%\System32\Config

folder as *.evt files.

Upvotes: 1

Robula
Robula

Reputation: 716

The app/service will need to run elevated at least once to create the log (unless you have UAC disabled), otherwise the CreateEventSource() will silently fail.

Upvotes: 0

Related Questions