I want to log messages as I traverse through code noting. We're using log4net for everything, but the problem that I'm finding is that in order to log, EVERYTHING has to have a dependency on ILog. There must be a better way and I have a few ideas but I wanted to see what you guys think. I don't want to have every class needing an ILog, or do I?
Needing some guidance here. I want to log messages as I traverse through code noting. We're using log4net for everything, but the problem that I'm finding is...
It also depends on the level of logging you want. For instrumentation purposes and some more "horizontal" logging, why don't you consider dependency injection...
I am using Windsor, so I have IoC if I want it. That doesn't address the issue of having an ILog passed in to every constructor. Any way around that? On Wed,...
... If not ILog then what instead? There's quite a bit of upside (as far as log4net is concerned) when dealing with hierarchy and reuse of a single logging...
I think you missed what I'm asking, instead of having ILog in every class, can I instead call some class which has a static method on it and do this ...
I define my log in which ever class needs it like this: private static readonly ILog _planLog = LogManager.GetLogger(typeof(PlanController));You certainly do...
How do you set that up for testing then with the static class? Can't mock that (sans TypeMock) but wondering how to structurally set this up so I don't have...
In my projects I use something of this sort: private static readonly ILoggerService _logger = MyApplication.Services.Get<ILoggerService>(); and use the methods...
Here is what I put in all of my classes: private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); No...
So the question really is what does LogManager look like. That is a log4net class if I remember correctly, which means that you have to have log4net set up...
I add a reference to Log4net to my test class and move on. No app.config changes at all. The static reference to the logger handles instantiating the logger,...
Why not just use Windsor? Use Castle's ILogger ... and it is all automatic ... is there something in the thread I am missing 'cos it all seems a bit simple...
Still you would then have to have a param to each constructor for ILogger right? And that is what I'm trying to avoid. On Wed, Jun 18, 2008 at 12:12 PM, Casey...
so on every class instead of having a param in the constructor, you're saying I should have a public property? On Wed, Jun 18, 2008 at 12:50 PM, Casey Charlton...
... You'd be using Windsor logging facility: http://www.castleproject.org/container/facilities/v1rc3/logging/index.html If your class is known to Windsor and...
Yep, constructor properties Shouldnt be used for cross cutting concerns like logging ... Put ILogger as a public property on the class, use the nulllogger as...
In your IoC configuration : container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Console)); In your class: public class MyClass { private...
OK, I posted a code sample that used straight Log4net to this thread. It used less code, it is just as configurable, and is just as testable (I think it is...
This supports any logger not just log4net, has no code to maintain, and as Tim is already using Windsor it is an elegant solution Casey On 18 Jun 2008, at...
Regardless of all the good magic afforded by IoC containers, having a class expose its logger (including a setter, no less!) smells weird--not necessarily bad...
Would you prefer a concrete dependency on a static class? Or would you prefer that each class knew how to create an instance of the logger? Or would you prefer...