[ 
https://issues.apache.org/jira/browse/LOG4NET-290?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13797734#comment-13797734
 ] 

Dmitry Naumov commented on LOG4NET-290:
---------------------------------------

Walden,
I do understand the need of lazy arguments evaluation, but there are two things 
I'm concerned about.
First one I've mentioned earlier - useless code which is already exist:
{code}
public static void DebugExt(this ILog logger, object message)
{
    if (logger.IsDebugEnabled)
    {
        logger.Debug(message);
    }
}
{code}

Second thing is bit harder to explain. Current logging implementation works 
such a good way, that if you call
{code}
logger.InfoFormat("Type {0} not found in assembly '{1}'", typeName, 
assemblyName);
{code}
it doesn't simply format string if INFO is enabled. It keeps template and 
arguments as separate things until they, as LoggingEventData inside 
LoggingEvent, reach appender. This allows to do quite interesting things like 
custom appender which writes to database and does automatic deduplication based 
on template part of logging event. This is similar to Serilog idea by Nicholas 
Blumhardt. Why am I talking about in context of recent changes? Because adding 
lambda like this kills whole idea:
{code}
public static void DebugExt(this ILog logger, Func<object> callback)
{
    if (logger.IsDebugEnabled)
    {
        logger.Debug(callback());
    }
}
{code}

I expect that usage of this method will look like this:
{code}
logger.DebugExt(() => string.Format("Total value is {0}", 
CalculateTotalValue());
{code}

After that it's much harder to extract actual arguments of template.
I understand that it is just my opinion and my case, but it was so good that 
log4net keeps these things (template and args) separated and I was impressed 
about it.

> Add Lambda-based ILog-Extensions (embedded log.IsEnabled)
> ---------------------------------------------------------
>
>                 Key: LOG4NET-290
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-290
>             Project: Log4net
>          Issue Type: New Feature
>          Components: Core
>    Affects Versions: 1.2.10
>            Reporter: Lars Corneliussen
>            Assignee: Dominik Psenner
>             Fix For: 1.2.12
>
>         Attachments: LOG4NET-290-doc.patch, LOG4NET-290.patch
>
>
> This statement:
>     if (log.IsDebugEnabled) log.DebugFormat("x: {0}", 123)
> Could be nicely shortened to:
>     log.Debug( m=>m("value= {0}", obj.Value) );
> I'm already apache committer (NPanday Incubator Project) and would be happy 
> to help with this interface. The simplest thing would be to offer it as 
> static Extension-Methods to ILog.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to