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

Jean-Francois Beaulac commented on LOG4NET-553:
-----------------------------------------------

Of course it would be simpler to just have a PatternLayout for the Category in 
the DebugAppender. By default it would be initialized to "%logger" and users 
could set the pattern to empty string to not output anything in the category, I 
created the ReturnsNullLayout class as per my understanding of the first 
proposal to have a SecondaryLayout that always returns null.

As for passing null in the category parameter of the Debug.Write() method, 
there is nothing specific about it in the documentation. The TraceListener 
class handles it like so (from reference source 4.6.2):

{code:java}
public virtual void Write(string message, string category) {
    if (Filter != null && !Filter.ShouldTrace(null, "", TraceEventType.Verbose, 
0, message)) 
        return;

    if (category == null)
        Write(message);
    else
        Write(category + ": " + ((message == null) ? string.Empty : message));
}
{code}

But maybe it would be safer to call the Debug.Write(string) method if its null, 
since anyone can plug in their own TraceListener and the Write(string, string) 
method is virtual, someone could override it in a way that does not handle null 
category correctly.

So what do you think if my patch:
 - Change Category property of DebugAppender to PatternLayout type, initialized 
with the pattern ""%logger"" to preserve actual behavior. Users can set the 
pattern to an empty string or the field to null to not have the category 
outputted.
 - if m_category == null, call Debug.Write(string)
 - if m_category != null, call Debug.Write(string, string)
 - No modifications to LayoutSkeleton (no need for the virtual specifier in the 
Format(LoggingEvent) method)
 - No need for ReturnsNullLayout class
 - Update tests and solution files accordingly

> DebugAppender configuration should give the possibility to disable outputting 
> loggerName as category
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LOG4NET-553
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-553
>             Project: Log4net
>          Issue Type: New Feature
>          Components: Appenders
>    Affects Versions: 2.0.7
>            Reporter: Jean-Francois Beaulac
>         Attachments: log4net-DebugAppenderCategory2.patch, 
> log4net-DebugAppenderCategory.patch, 
> OutputCategoryParam-DebugAppender.cs.patch
>
>
> The DebugAppender always uses the 
> {{System.Diagnostics.Debug.Write(string,string)}} overload passing in the 
> loggername as the category parameter.
> It should be possible to omit the category parameter if having the loggername 
> as category is not desired.
> Attached is a patch implementing the desired new feature, which would be 
> activated by configuration:
> {code:xml}
> <appender name="DEBUG" type="log4net.Appender.DebugAppender">
>     <outputCategory value="false"/>
>     <layout type="log4net.Layout.PatternLayout">
>         <conversionPattern value="%-5level: %message%newline"/>
>     </layout>
>   </appender>
> {code}
> In my patch, the outputCategory parameter defaults to true, so the behavior 
> doesnt change unless the new configuration is used.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to