Why not?  It makes it so much fun to read!  ;)

-----Original Message-----
From: Ron Grabowski [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 18, 2005 10:37 AM
To: Log4NET User
Subject: RE: Log4Net only for the committed techies


Please don't write code like that :)

--- "Hart, Leo" <[EMAIL PROTECTED]> wrote:
> For the garbage problem, can't you just use a StringBuilder there to 
> avoid that?  For instance:
> 
> Log.Debug(new StringBuilder("My name is[").append(name).append("].");
> 
> -----Original Message-----
> From: Jaroslaw Kowalski [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 18, 2005 10:12 AM
> To: Log4NET User
> Cc: [EMAIL PROTECTED]
> Subject: Re: Log4Net only for the committed techies
> 
> 
> Hi Ron,
> 
> Some answers to your questions inside:
> 
> > Which leads me to believe that people often use less than 3
> > placeholders. Do people really use 10 or 15 placeholders at a time?
> 
> > Yuck. I don't think there's anything wrong with this:
> >
> > log.Debug("My name is [" + name + "].");
> 
> The problem is: garbage. When you write the code above you'll have at 
> least one (perhaps two) memory allocations.
> This code:
> 
> log.Debug("My name is [{0}].", name)
> 
> has zero memory allocation for non-logging case. This can be very 
> useful in
> tight loops. With log4net you have to comment out your logging code.
> With 
> NLog there's no need to do that - you just disable the Debug level
> for 
> particular logger and you're done.
> 
> NLog is optimized for one placeholder (zero-garbage) but in the future
> this 
> may be changed to support more than one parameter.
> 
> To do the same with log4net efficiently you'd have to:
> 
> if (log.IsDebugAllowed)
> {
>     log.Debug("My name is [" + name + "].");
> }
> 
> >> LogLevel level = LogLevel.Debug;
> >>
> >> logger.Log(level, "aaaa");
> >
> > Is this high level programmer? I'd be curious where this may be
> > useful. I see it as another local variable that I need to keep
> track
> > of.
> 
> It may be useful when you're wrapping NLog with some other logging 
> layer, which is not so uncommon. Otherwise you'd have to use a switch:
> 
> switch (...)
> {
>     case Debug: log.Debug(...); break;
>     case Error: log.Error(...); break;
>     case Fatal: log.Fatal(...); break;
>     case Info: log.Info(...); break;
> ...
> }
> 
> Jarek
> 

Reply via email to