3

The officially released Ninject 2 no longer includes reference to the WebForms-specific functionality for IoC for WebForms, MasterPages, etc. It's now separated out into plugins/extensions; which in this case is the http://github.com/idavis/ninject.web extension. My problem however is that there's a dependency on log4net (or NLog) and I can't find any documentation on how to configure it to either integrate with my current log4net configuration, or remove it altogether (i.e. set the logging to null so I don't conceivably have two log4net configurations running).

http://markmail.org/message/7iv7nltanz6ve4ga#query:Error%20activating%20ILoggerFactory%20ninject.web+page:1+mid:6o4q6ee2js2k4gfp+state:results references others with the same issue, but again, no real documentation on what to do with it. I've looked through the source for all of it, and must be missing something obvious.

Can anyone point me in the right direction for the best way of dealing with this so I can still easily integrate Ninject with WebForms, but not have extraneous logging services running? Or not worry about something like the following on the Global.asax:

    protected override IKernel CreateKernel()
    {
        IKernel kernel =
        new StandardKernel(new SomeMyModule(), new Log4netModule());
        return kernel;
    }

I'm currently kickstarting my log4net configuration in global.asax via

 private readonly static ILog Log = LogManager.GetLogger(typeof(Global));:
Ted
  • 7,122
  • 9
  • 50
  • 76
  • Looks like ninject needs a NullLogger? Have you tried *not* adding any logging module? – Mauricio Scheffer Feb 27 '10 at 02:02
  • Just a small point, you mention 'kickstarting' log4net - you do know that that line just says "get me one for me" as opposed to "We're going to be using logging around here" (you prob doo - just wanted to make sure) http://stackoverflow.com/questions/1261158/log4net-initialisation – Ruben Bartelink Feb 27 '10 at 07:44
  • Mauricio - yes, results in an "no ILogger specified" exception. Which makes sense because there is no NullLogger for Ninject. Ruben - yes, I know. log4net requires that LogManager.GetLogger be a) called in the same assembly as where the log4net config is located (which rules out another assembly that my error module belongs to) and b) as soon as possible. Calling it where I do in such a way fulfils both. – Ted Mar 01 '10 at 17:41
  • Mauricio - correction: it turns out not adding any logging module is the correct configuration, but my previous attempts on that end must have coincided with not having my existing log4net configuration initialized yet (leading to the no ILogger configured exception). Oops. – Ted Mar 01 '10 at 18:20

1 Answers1

3

While Ninject.Web has ILogger properties, it does not log anything.

If you want to disable Ninject.Extensions.Logging entirely, create and bind an implementation of ILoggerFactory that returns null from all methods.

Or if you want to enable it with log4net, fetch Ninject.Extensions.Logging from ninject.org and reference Ninject.Extensions.Logging.Log4net from your project. It will be automatically loaded by Ninject 2.0.

If you are building Ninject.Web from source, you could remove the logging extension by:

  • drop the reference to that assembly
  • remove the ILogger member from the 5 classes that have it
Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77
  • "It will be automatically loaded by Ninject 2.0" are the magic words in that it uses my already existing log4net configuration. – Ted Mar 01 '10 at 18:20