NServiceBus
NServiceBus copied to clipboard
ProfileManager logger is initialised to NullLogger before custom loggerfactory is set up
Version 5 now has sensible defaults for logging. So logging will still occur from ProfileManager even if logging is not yet configured.
In Version 5 IWantCustomLogging is obsoleted. The replacement is to us IWantCustomInitialization and configure logging before Configure.With()
I have an endpoint which implements IWantCustomLogging and sets logging to NLog.
- The GenericHost constructor instantiates a ProfileManager.
- The ProfileManager has a static ILog which is set to LogManager.GetLogger(typeof(ProfileManager))
- At this point LogManager._loggerFactory has not been changed from NullLoggerFactory
- The GenericHost runs PerformConfiguration() and the first thing that happens is the LogManager._loggerFactory is set to an NLogFactory
- some time afterwards ProfileManager.ActivateProfileHandlers() is run - but logging is not emitted because its ILog has been already set to a NullLogger
I'm not sure what the best fix is - happy to put together a PR once a fix is identified.
perhaps the quickest fix is to move this:
profileManager = new ProfileManager(assembliesToScan, specifier, args, defaultProfiles);
ProfileActivator.ProfileManager = profileManager;
out of the GenericHost constructor and moved to after this point in PerformConfiguration():
if (specifier is IWantCustomLogging)
(specifier as IWantCustomLogging).Init();
that way the ProfileManager static ILog will get a valid logger...