1

I am writing a windows service in MS Visual Studio 2012.

I used:

private const string SERVICE_NAME = "Minifilter Windows Service";
private const string LOG_TYPE = "Application";
public EventLog elMinifilter = new EventLog(SERVICE_NAME);// remove STATIC

this.AutoLog = false;// UPDATE
elMinifilter.Source = SERVICE_NAME;
elMinifilter.Log = LOG_TYPE;


if (!EventLog.SourceExists(elMinifilter.Source))
    EventLog.CreateEventSource(elMinifilter.Source, elMinifilter.Log);

// Write log
elMinifilter.WriteEntry("Start!", EventLogEntryType.Information);

At Computer Management >> System Tools >> Event viewer >> Application and Service Logs, I couldn't find the event log which I created. Is it right?

Where can I find event log of windows service?

Thanks all!!!

GSP
  • 574
  • 3
  • 7
  • 34
  • Did you run the code elevated? – Harry Johnston Jan 09 '15 at 04:45
  • Sorry, I don't understand what you say. Please expand more detail. – GSP Jan 09 '15 at 04:46
  • Did you use "run as administrator" ? – Harry Johnston Jan 09 '15 at 04:49
  • Thanks, I used Windows Driver Kit (Run as administrator). I used "sc create wsminifilter binpath= path_to_exe" and "sc start wsminifilter" to run service. Is it right? – GSP Jan 09 '15 at 04:54
  • Oh, the code is actually running in a service. I had misunderstood. It might be easy to debug if you try it as a normal application first. – Harry Johnston Jan 09 '15 at 04:57
  • I guess `elMinifilter` is not initialized correctly, noted that it is `static`. Please refer to [How to: Log Information About Services](http://msdn.microsoft.com/en-us/library/f6567h1s%28v=vs.110%29.aspx), the difference is `EventLog.CreateEventSource` is called _before_ configuring the event log instance, `eventLog1.Source = "MySource";`. In your code, `eventLog1.Source = "MySource";` is called _before_ `EventLog.CreateEventSource`. – kennyzx Jan 09 '15 at 05:09
  • I have updated my code as link which @kennyzx gived. But I could find the event log. Where Can I find it? – GSP Jan 09 '15 at 06:50
  • 2
    You can find it under Event Viewer->Windows Logs->Application, not Application and Service Logs. – kennyzx Jan 09 '15 at 07:16

0 Answers0