1
votes

I have a created a windows service and i am installing it using installutil. In the project installer i am creating a custom event log. But when my service starts my all logs are going to the "Application" instead of my cuustom log. Below is the code which i have added to installer.

// Create Event Source and Event Log     
EventLogInstaller logInstaller = new EventLogInstaller();
logInstaller.Source = "MyServices";
logInstaller.Log = "MyService Events";

Installers.Add(logInstaller);

Furthurmore the name of service is MyService.exe.

When I uninstall and re-install the service, i installation fail with the following install log;

Running a transacted installation.

Beginning the Install phase of the installation. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.

An exception occurred during the Install phase. System.ArgumentException: Source MyServices already exists on the local computer.

The Rollback phase of the installation is beginning. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.

The Rollback phase completed successfully.

The transacted install has completed.

And this is how i write log entry;

EventLog.WriteEntry("MyServices", logMessage, logType);

Can someone please help me what wrong i am doing.

1

1 Answers

0
votes

When you add a new Log Source you have to restart the server for the log source to be found properly.

You also need your installer to be aware of if the log source is already there.

So add a quick check for the log source before you add it and restart the server after installing the first time to get the log source to work.