Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service output not showing up in Event Log

I am trying to follow this walkthrough.

I'm using Visual Studio 2010 Premium.

The only events I see in Server Explorer or in Event Viewer are "Service started successfully." and "Service stopped successfully."

Here is the service code:

namespace MyNewService
{
    public partial class MyNewService : ServiceBase
    {
        public MyNewService()
        {
            InitializeComponent();
            if (!EventLog.SourceExists("MySource"))
            {
                EventLog.CreateEventSource("MySource", "MyNewLog");
            }
            eventLog1.Source = "MySource";
            eventLog1.Log = "MyNewLog";
        }

        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
        }

        protected override void OnStop()
        {
            eventLog1.WriteEntry("In onStop.");
        }
    }
}
like image 376
feenst Avatar asked Sep 23 '11 21:09

feenst


People also ask

How do I view Windows Service logs in Event Viewer?

Click Start > Control Panel > System and Security > Administrative Tools. Double-click Event Viewer. Select the type of logs that you wish to review (ex: Windows Logs)

How do I fix Event Log service is unavailable?

Right-click on the Windows Event Log service and click on Start. In case the service is already running, click on Restart. You might also be prompted for the administrator password, enter it accordingly. Once the Windows Event Log service starts successfully, the error should be solved.

How do you debug a service?

To debug a service, you must start the service and then attach a debugger to the process in which it is running. You can then debug your application by using all of the standard debugging functionality of Visual Studio.


1 Answers

I had the same issue with Visual Studio 2010 Professional on Win 7 64. My newly compiled service was installed with InstallUtil.exe running as Administrator. It started and stopped correctly. No exceptions but no amount of refreshing the Event Viewer revealed a new event log. Fran71's suggestion worked for me: I closed the Event Viewer and reopened. Voilà, the newly created application log file appeared.

like image 70
FumblesWithCode Avatar answered Oct 05 '22 11:10

FumblesWithCode