Re: [topshelf-discuss] Topshelf logging and hostfactory errors

1,883 views
Skip to first unread message

Mario Pareja

unread,
Jun 15, 2012, 7:38:38 AM6/15/12
to topshelf...@googlegroups.com
Here's a quick shot in the dark: try passing empty string "" to UseLog4Net.

The official site REALLY needs to include how to enable logging. It is extremely frustrating to try out for the first time (in a long time) and not have it not give any form of feedback.

On 2012-06-15, at 5:59 AM, Keith Stenson <kstenson@gmail.n com> wrote:

Hi Guys,

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:

From: public static class HostFactory.......

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

Dru Sellers

unread,
Jun 15, 2012, 8:14:24 AM6/15/12
to topshelf...@googlegroups.com
My apologies everyone,

When we switched over to the new logging I failed to update the docs. I will do that today.

-d

Mario Pareja

unread,
Jun 15, 2012, 8:25:51 AM6/15/12
to topshelf...@googlegroups.com
Hey Drew, 

Is it possible to get the default trace logger to output to the console when you're just running from the command line?

Thanks,

Mario

Dru Sellers

unread,
Jun 15, 2012, 10:26:03 AM6/15/12
to topshelf...@googlegroups.com
how is this for docs on the logging?


-d

Dru Sellers

unread,
Jun 15, 2012, 10:46:22 AM6/15/12
to topshelf...@googlegroups.com
I would assume that we can get the TraceSource to go to the console, but I have never used them.

@chris, any ideas?

-d

Mario Pareja

unread,
Jun 15, 2012, 10:47:06 AM6/15/12
to topshelf...@googlegroups.com
Much better. I think you'll save people hassles by including a logger one-liner in the Getting Started code sample.  Just add "Logger.UseLogger(new NLogLogger());" to the top of the HostFactory configuration example since people will inevitably copy-and-edit that sample code and inevitably end up frustrated because they don't see any output. (I suggested NLog since so people don't need to think about XML files when they are just trying to spike things out.)

Is there a way for others to contribute to the documentation?

Dru Sellers

unread,
Jun 15, 2012, 10:48:24 AM6/15/12
to topshelf...@googlegroups.com
No, not with the current model. If I switch to the MT style docs then yes, people can easily contribute. Probably the best reason to switch.

-d

Keith Stenson

unread,
Jun 15, 2012, 11:24:37 AM6/15/12
to topshelf...@googlegroups.com
Hi Guys, thanks for your help on this. It's really appreciated! 



Keith
Reply all
Reply to author
Forward
0 new messages