Recommended Log4Net Registration in MVC 4 Application?

Mar 23, 2013 at 8:48 PM
Hi,
I'm pretty new to IoC and trying to set up a new app with best practices all the way around. I'm going with SimpleInjector and wondering if anyone has a recommended way of using Log4Net with it? The way I've used it before is to use its factory method for creating a new logger in every class, so not sure how that supposed to work with a container (if at all).

Any suggestions are much appreciated.

Thanks!
Coordinator
Mar 23, 2013 at 9:50 PM
I've used it before is to use its factory method for creating a new logger in every class
The best advice I can give you about this is in this Stackoverflow answer.
Mar 24, 2013 at 12:30 AM
Thanks. I should have said 'every class that needs logging'. I'll only want it injected on those classes that need it. One thing I've done in the past in Autofac is to use this bit of code that allows for using Autofac to create the instance yet still get the info about the class it's being injected into:

http://code.google.com/p/autofac/wiki/Log4NetIntegration

Is there a way to do something similar in SimpleInjector?

Thanks again....
Coordinator
Mar 24, 2013 at 8:52 AM
Simple Injector allows you to do Context Based Injection, which is explained here in the documentation. I think this is what you want.
Marked as answer by dot_NET_Junkie on 11/5/2013 at 7:38 AM