Search the web
Sign In
New User? Sign Up
altdotnet · Alt Dot.Net Discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Facade....Dependecy Guidance   Message List  
Reply | Forward Message #10109 of 23247 |
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 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?

Thoughts?


Wed Jun 18, 2008 3:37 pm

timbarcz
Offline Offline
Send Email Send Email

Forward
Message #10109 of 23247 |
Expand Messages Author Sort by Date

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...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
3:37 pm

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...
Hugo Batista
aranhix
Offline Send Email
Jun 18, 2008
3:45 pm

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,...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
3:48 pm

... 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...
M. David Peterson
x5_hacker
Offline Send Email
Jun 18, 2008
3:46 pm

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 ...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
3:49 pm

I define my log in which ever class needs it like this: private static readonly ILog _planLog = LogManager.GetLogger(typeof(PlanController));You certainly do...
Paul Cowan
dagda1970
Offline Send Email
Jun 18, 2008
3:56 pm

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...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
4:00 pm

I have the log4net element in the App.Config of my test project.Or am I misunderstanding your question?You can mock the ILog.You could look at the...
Paul Cowan
dagda1970
Offline Send Email
Jun 18, 2008
4:17 pm

... I meant loggingfacilitydagda1@... To: altdotnet@...: dagda1@...: Wed, 18 Jun 2008 16:16:53 +0000Subject: RE:...
Paul Cowan
dagda1970
Offline Send Email
Jun 18, 2008
4:29 pm

... one > thing. Are you meaning that you want to test the logging itself?...
Colin Jack
colin.jack
Offline Send Email
Jun 18, 2008
6:19 pm

In my projects I use something of this sort: private static readonly ILoggerService _logger = MyApplication.Services.Get<ILoggerService>(); and use the methods...
Paulo Mouat
p_mouat
Offline Send Email
Jun 18, 2008
4:15 pm

Can you provide the code so I can view. I think what you're doing is exactly what I want to be doing....
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
4:18 pm

Here is what I put in all of my classes: private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); No...
Chris Brandsma
c_brandsma
Offline Send Email
Jun 18, 2008
4:29 pm

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...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
4:36 pm

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,...
Chris Brandsma
c_brandsma
Offline Send Email
Jun 18, 2008
4:52 pm

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...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
5:12 pm

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...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
5:42 pm

No Windsor fulfils optional dependencies on public properties...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
5:50 pm

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...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
5:52 pm

... 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...
Colin Jack
colin.jack
Offline Send Email
Jun 18, 2008
6:28 pm

Can you (or anyone) provide a concrete example, in other words code. I understand the concepts and I already have and am using Windsor....
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
6:37 pm

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...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
6:37 pm

Best explanation all day! Thanks. On Wed, Jun 18, 2008 at 1:36 PM, Casey Charlton <casey@...>...
Tim Barcz
timbarcz
Offline Send Email
Jun 18, 2008
6:37 pm

In your IoC configuration : container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Console)); In your class: public class MyClass { private...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
6:47 pm

And I just blogged it, because I forgot how long it took me to figure this out the first time, despite it being deceptively simple ...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
7:34 pm

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...
Chris Brandsma
c_brandsma
Offline Send Email
Jun 18, 2008
7:48 pm

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...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
7:54 pm

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...
Paulo Mouat
p_mouat
Offline Send Email
Jun 18, 2008
7:48 pm

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...
Casey Charlton
caseycharlton69
Offline Send Email
Jun 18, 2008
8:01 pm
First  | < Prev  |  Last 
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help