Installation project for Windows service and event log

I have an installation project that installs a Windows service.

We register the source of the event log in the user log that should be used by the winservice project (how and why it doesn’t matter).

My problem is that the installation project is trying to create a default event log source. By doing so, an error message appears ( "Error 1001" source XXX already exists on local computer ) and rollback.

I looked everywhere and I can’t find where the registration is done or how I can turn it off.

How do I force a Windows service or installation project to NOT create an event log source?

+7
source share
3 answers

You can remove the default EventLogInstaller :

 namespace MyService { [RunInstaller(true)] public partial class ProjectInstaller : Installer { public ProjectInstaller() { InitializeComponent(); // Remove the default Event Log Installer EventLogInstaller DefaultInstaller = null; foreach (Installer installer in serviceInstaller1.Installers) { if (installer is EventLogInstaller) { DefaultInstaller = (EventLogInstaller)installer; break; } } if (DefaultInstaller != null) { serviceInstaller1.Installers.Remove(DefaultInstaller); } } } } 

Alternatively, you can change the Log property:

 foreach (Installer installer in serviceInstaller1.Installers) { if (installer is EventLogInstaller) { ((EventLogInstaller)installer).Log = "MyLog"; break; } } 

Events will now be successfully logged in MyLog, and service start / stop events will still be logged in the application log.

(source: serviceInstaller component and its default EventLogInstaller )

+7
source

I assume that when you delete a service, something is deleted incorrectly, especially in the event log.

To restore the ability to reinstall the service, I discovered ( thanks to this article ) that you need to remove this key in the registry (regedit.exe):

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\YOURSERVICENAME 
+3
source

This is just an assumption based on my tests.

The installer project (or the WindowService class) automatically creates an event source with the same name as myService.ServiceName . This is most likely because Start / Stop messages are logged every time the service starts / stops. And these messages need a source.

In other words: you do not need to create a source with the same name as ServiceName, as it is done for you.

+2
source

All Articles