Hanno
Hanno

Reputation: 1027

Use log4net with Ninject logging extensions in WebForms application

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?

Upvotes: 0

Views: 418

Answers (1)

user484189
user484189

Reputation: 191

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

Upvotes: 1

Related Questions