Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup project for a windows service and the event log

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?

like image 334
jgauffin Avatar asked Feb 02 '11 13:02

jgauffin


People also ask

How do I setup a Windows project service?

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.

Where are logs for Windows services?

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)


1 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 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)

like image 56
user247702 Avatar answered Oct 17 '22 10:10

user247702