I'm trying to get Topshelf to log errors when it's trying to start up my service. I have added the Log4NetIntergration assembly and I'm using this host setup:
HostFactory.Run(x =>
{
x.Service<AcquireService>(s =>
{
s.SetServiceName("AcquireService");
s.ConstructUsing(name => container.Resolve<AcquireService>());
s.WhenStarted(svc =>
{
logger.Debug("Starting host service");
svc.Start();
StartWCFService(container);
logger.Debug("Successfully started host service");
});
s.WhenStopped(svc => svc.Stop());
});
x.RunAsLocalSystem();
x.SetDisplayName("Acquire.Service");
x.SetServiceName("Acquire.Service");
x.UseLog4Net("logging.config");
});
How ever I'm not getting any logging from Topshelf. Also if there is an un-handled exception when trying to start the service, Topshelf seems to be swallowing exceptions. I did some digging and it seems to be this part of the Topshelf code that's causing my problem:
public static void Run(Action<HostConfigurator> configure)
{
try
{
New(configure)
.Run();
}
catch (Exception ex)
{
_log.Error("The service exited abnormally with an exception", ex);
}
}
For some reason the the logger instance is not writing via log4net. Also should the host process swallow an exception like this? should throw after it's logged the exception?
Thanks for any advice you can give!
Keith