Why are Windows logs not showing up in the Application event log?
I created a C # Windows Service Mill Startup using the Windows Service Project Template. I was able to install it correctly and start and stop it without any problem.
However, when I go to the event viewer to see it start and stop, I get nothing.
Here's some sample code I'm testing:
public MyService()
{
InitializeComponent();
ServiceName = "My Data Service";
EventLog.Log = "Application";
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Starting My Data Service");
}
protected override void OnStop()
{
EventLog.WriteEntry("Ending MyData Service");
}
Also, my OS is Windows Vista.
+1
a source to share
2 answers
If you want it to be logged by default then use
EventLog.WriteEntry("Starting My Data Service", EventLogEntryType.Information);
Of course, you must ensure that the service is running under an account with sufficient logging privileges and to "run as a service".
Found this example on SO, Best way to write to event log
Here is an example where you also specify the source rather than display it as .NET Runtime ... MSDN example
+4
a source to share