0

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)

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156

1 Answers1

0

as you found out, it's an ordering issue. Happy to take a patch to fix that though.

SerialSeb
  • 6,701
  • 24
  • 28
  • I wonder if it's worth the effort working on patches for OpenRasta 2.0.x, which I'm currently on (2.0.3). I guess I should start looking at going 2.1. Version 3 is still in the making, if I'm not mistaken... – Evgeniy Berezovsky Jan 25 '12 at 01:31
  • Well seeing as 2.0 is not in any code repository anymore i'd say no, all the work is now in the 2.1 branch (the master of each repo). – SerialSeb Jan 25 '12 at 16:09
  • I'm working on deploying an OpenRasta service, and am having this issue. I want the OR logs to go to my logging implementation, but it's not working. Is there a way we can do this without building our own fork of OR? – Dave Nichol Apr 11 '12 at 20:32