Reputation: 27
I use NServiceBus 2.6.
I use a log4net.config file & initialize logging facilities by code in my endpoint:
SetLoggingLibrary.Log4Net(() =>
XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config")));
When I run NServiceBus.Host.exe normally it logs well, but when I deploy it as a windows service using /install, nothing is logged anymore.
It works if I use the code based way:
SetLoggingLibrary.Log4Net<RollingFileAppender>(...)
Any ideas why...?
Upvotes: 0
Views: 843
Reputation: 515
When running a process as a windows service, it will not by default set the current directory to the place where your binaries are located. This means that when you look for "log4net.config" it will actually search in c:\windows\system32.
Try this (before SetLoggingLibrary is called):
System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
or, modify your code to something like this:
SetLoggingLibrary.Log4Net(() =>
XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"))));
Upvotes: 1