0

After some struggling I managed to get a working ASP.NET webforms application that uses the Ninject logging extension and log4net as logging framework. (credits to this blog for the basics). But I have some questions on how to continue.

First, I needed to make the ILogger property public, because it remained null if it was private or protected. So now I have this:

[Inject]
protected ILogger _logger { get; set; }

Instead of:

private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

I can live with it, but it seems strange.

Another thing is the ThreadContext that log4net uses to fill the current context. I can still use it like this

using (ThreadContext.Stacks["NDC"].Push(MethodBase.GetCurrentMethod().Name))
{
     _logger.Info("test");
}

But offcourse that takes away all the abstraction that I just added.. So I'm looking for some experiences / best practices that other people may have with this scenario.

Additional question: I've upgraded log4net to 1.2.11.0 which is the current version in NuGet, and now Ninject.Logging.log4net is broken because it expects version 1.2.10.0 ... is there a way to fix that?

Hanno
  • 1,017
  • 11
  • 18

1 Answers1

1

Additional question: I've upgraded log4net to 1.2.11.0 which is the current version in NuGet, and now Ninject.Logging.log4net is broken because it expects version 1.2.10.0 ... is there a way to fix that?

Did you try to fix the allowed versions with [xx] in the Packages.config file ?

  <package id="log4net" version="1.2.10"  allowedVersions="[1.2.10]" /> />

It will prevent next updates to upgrade to 1.2.11 or more.

http://docs.nuget.org/docs/reference/versioning

user484189
  • 191
  • 5
  • I'm not sure how to use this.. I keep ending up with version 1.2.11. – Hanno Mar 21 '12 at 07:53
  • I edit my answer, it is the allowedVersion attribute that must be modified. You have to uninstall the 1.2.11 version at first. Then update your packages.config file, and run an install-package command. – user484189 Mar 22 '12 at 11:06