Re: [topshelf-discuss] How to tell Topshelf not to create a EventLog Source on service installation (or customize it)

767 views
Skip to first unread message

Travis Smith

unread,
Apr 10, 2013, 7:03:25 AM4/10/13
to topshelf...@googlegroups.com
If this is something you need, taking a swing at a pull request would be the quickest way to get it in. I would start with opening an issue on GitHub though. 

-Travis


On Wed, Apr 10, 2013 at 6:59 AM, Stéphane Erbrech <stephane...@gmail.com> wrote:
When running myservice.exe install, an eventlog source is created under the Application EventLog. I would rather specify it myself, or not have it at all.
I quickly read through the code, and I don't see anything that creates an EventLog source explicitely. (https://github.com/phatboyg/Topshelf/blob/master/src/Topshelf/Runtime/Windows/HostServiceInstaller.cs). 
It's just seems to use the internal TransactedInstaller and ServiceInstaller.

var installer = new ServiceInstaller
{
      ServiceName = settings.ServiceName,
      Description = settings.Description,
      DisplayName = settings.DisplayName,
      ServicesDependedOn = dependencies
};

After some googling, it seems that the ServiceInstaller does this.
From MSDN :

When the installation is performed, it automatically creates an EventLogInstaller to install the event log source associated with the ServiceBase derived class. The Log property for this source is set by the ServiceInstaller constructor to the computer's Application log. When you set the ServiceName of theServiceInstaller (which should be identical to the ServiceBase.ServiceName of the service), the Source is automatically set to the same value. In an installation failure, the source's installation is rolled-back along with previously installed services.

But there is no clear way to customize it. Almost no way...

ServiceInstaller svcInstaller = new ServiceInstaller(); foreach (var installer in svcInstaller.Installers) { Console.WriteLine(installer.GetType()); } Console.Read();

if you run this in a console app, it will print System.Diagnostics.EventLogInstaller

So we could in fact simply remove it after creation, or change it if TopShelf would provide some way of customizing it by touching the default one.

ServiceInstaller svcInstaller = new ServiceInstaller(); var evtlogInstaller = svcInstaller.Installers.OfType<EventLogInstaller>().First(); evtlogInstaller.Log = "MyEventLogName"; evtlogInstaller.Source = "MySource";

I would gladly help the project and send such a feature as a pull-request if this is interesting.

--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chris Patterson

unread,
Apr 10, 2013, 4:42:02 PM4/10/13
to topshelf...@googlegroups.com
Open an issue (on Topshelf/Topshelf) and then create the pull request in response to that issue. I think it's a great idea.
Reply all
Reply to author
Forward
0 new messages