I created my own ILogger implementation and register an instance via
ResourceSpace.Uses.Resolver.AddDependencyInstance<ILogger>(...)
inside the
using (OpenRastaConfiguration.Manual)
block.
This works fine for most log messages, however some classes in OpenRasta try to figure out their ILogger instance before the DI is ready, like HostManager:
static HostManager()
{
Log = DependencyManager.IsAvailable
? DependencyManager.GetService<ILogger>()
: new TraceSourceLogger();
}
In my case (and I suspect the general case), IsAvailable is false, so it defaults to TraceSourceLogger.
As static ILogger HostManager.Log is not a public property, I hacked it and made it public so that I can now set it.
When it comes to InternalDependencyResolver, which is always initialized to new TraceSourceLogger() on object construction, it does have a publicly settable ILogger Log property, so I could just use that.
Now all of OpenRasta's log messages that I've encountered so far go to my custom ILogger.
Does anyone know of a way to get all of OpenRasta's classes (I did not check systematically and might have missed a class or two) to log to a custom ILogger without having to hack the sources? (It's always nice to know that upgrading OpenRasta won't require repatching and rebuilding)
as you found out, it's an ordering issue. Happy to take a patch to fix that though.