Log4net working when Windows Server Service control working, but not when using the c:\service.exe start command

36 views
Skip to first unread message

Adam Schaible

unread,
Oct 12, 2017, 3:59:32 PM10/12/17
to topshelf-discuss
Hi Guys,

I'm running into an issue here.  I'm using the Topshelf / Autofac integration with this code:

                x.Service<MyService>(s =>
                {
                    s.ConstructUsing(() =>
                    {
                                               var builder = new ContainerBuilder();
                        builder.RegisterModule(new MyServiceModule());
                                               var container = builder.Build();
                        return container.Resolve<MyService>();
                    });
                    s.WhenStarted((nsm, hostControl) => nsm.Start(hostControl));
                    s.WhenStopped((nsm, hostControl) => nsm.Stop(hostControl));
                });

I'm also using Log4Net with static loggers in each class, like:

private static readonly ILog Logger = LogManager.GetLogger(typeof(Program));

When I start the service with the windows services application, log messages from MyService.Start are logged.  When I start it from the TopShelf command line (MyService.exe start), log messages are not written to the log file.

I'm configuring Log4Net with the xml configurator in AssemblyInfo.cs

Does anyone know what would lead to the different behavior between the two service start mechanisms?

Thanks!
-Adam


Adam Schaible

unread,
Oct 12, 2017, 4:15:25 PM10/12/17
to topshelf-discuss
Clarifying my initial post - after the service is started, logging works.  But logging inside the nsm.Start method does not write to the log appender.

Thanks,
-Adam
Reply all
Reply to author
Forward
0 new messages