I got a setup project that installs a windows service.
We are registering a event log source in a custom log which should be used by the winservice project (how and why is not important).
My problem is that the setup project tries to create an event log source per default. By doing so it get's an error message ("Error 1001" source XXX already exists on local computer
) and rolls back.
I have looked everywhere and I cannot find where the registration is done or how I can turn it off.
How can I force the windows service or setup project to NOT create an event log source?
Create Setup Project for Window Service Open a dialog box, go to left pane under Installed Templates > Other Project Types > Setup and Deployment > Visual Studio Installer and go to the right pane and select the project as a “Setup Project” and click on the OK button.
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)
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 modify the Log
property:
foreach (Installer installer in serviceInstaller1.Installers)
{
if (installer is EventLogInstaller)
{
((EventLogInstaller)installer).Log = "MyLog";
break;
}
}
Now events will be successfully logged to MyLog, and service start/stop events will still be logged to the Application log.
(source: serviceInstaller component and its default EventLogInstaller)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With