Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Problem with replacing LogManager.GetLog

Open beachwalker opened this issue 5 years ago • 3 comments

If I want to replace the logger of Caliburn.Micro I can register the function to resolve it to the LogManager.GetLog static property. However, this can be done only after finishing the configuration if the IoC is required (means the Bootstrapper's configuration needs to be finished).

If I step through with the Debugger I can see that the view is calling it too early. The following code snippet is from my Bootstrapper class that is derived from BootstrapperBase.

image

… ending up in a message that the IoC is not yet configured. How to replace the logger then? Where do the previous logging messages go? Somehow the View class of CM is calling the logger too early.

I guess, Logging should not start earlier than the finish of configuration, right?

beachwalker avatar Mar 22 '20 13:03 beachwalker

Most of the loggers are defined as static properties which means they'll be created early but nothing will be logged.

I'm not sure of any easy way to change this other than moving all logs within the framework to Lazy or something equivalent.

nigel-sampson avatar Mar 23 '20 20:03 nigel-sampson

Most of the loggers are defined as static properties which means they'll be created early but nothing will be logged.

I'm not sure of any easy way to change this other than moving all logs within the framework to Lazy or something equivalent.

I mean there is a call to the static Logger before the Configure method was finished. I is like calling the IoC to resolve before it has been built. I don't know the logging framework before it can be resolved. Maybe not important, but the current implementation tries to log something to nirvana. Actually previous logger setting... but where would you expect to see that output?

beachwalker avatar Apr 15 '20 22:04 beachwalker

Most of the loggers are defined as static properties which means they'll be created early but nothing will be logged.

That global static usage changed a bit with net core and generic host usage.

beachwalker avatar Apr 15 '20 22:04 beachwalker