You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Hart, Leo" <Le...@FMR.COM> on 2005/07/14 20:41:47 UTC

Using %C, %F, %l, %L and %M in ConversionPattern

Hello,
 
I'm interested in added method name data in my logging messages, so I've
set up my RollingFileAppender like this:

	<appender name="File - Support"
type="log4net.Appender.RollingFileAppender">
	  <param name="File"
value="c:\\LogFiles\\ReferenceApp\\ReferenceApp" />
	  <param name="AppendToFile" value="true" />
	  <param name="DatePattern" value="  - yyyy-MM-dd.'log'" />
	  <param name="RollingStyle" value="Date" />
	  <param name="StaticLogFileName" value="false" />
	  <layout type="log4net.Layout.PatternLayout">
	   <param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd
HH:mm:ss, fff} | %t | %c | %M | %t | %m%n" />  
	  </layout>
	 </appender>

%M tells Log4Net to output the name of the method within which the
logging statement was generated.
 
Now, I have Ceki Culcu's book for log4j (I was a Java developer in a
previous life).  Within that he states:

	On certain platforms, generating the caller class information
can be excruciatingly slow.  Thus, the user of the C, F, l, L, and M
conversion characters should be avoided unless execution speed is not an
issue.

My question is, given that I'm using Log4Net (1.2.8b) and not Log4J and
my platform is .NET 1.1, is this statement still true?  And if so, does
anyone have any benchmarks indicating how much of a performance penalty
will be taken for using the %M character?
 
Thanks,
Leo Hart

Re: Using %C, %F, %l, %L and %M in ConversionPattern

Posted by Ron Grabowski <ro...@yahoo.com>.
Can the method name be extracted in Release mode as well?

How does building in Debug or Release mode affect the timings on your
machine?

--- Niall Daley <ni...@apache.org> wrote:

> Leo,
> 	In order to generate the method name log4net has to throw an
> exception and check the stack trace so, yes, it is very much slower
> than
> not doing so. As a rough guide line, on my machine it takes
> approximately
> 0.5 seconds to log 10000 messages with out %M and 6.4 seconds with it
> in
> the pattern. If you really want to use this you should evaluate the
> performance penalty in your own environment however.
> 
> 		Niall
> 
> On Thu, 14 Jul 2005, Hart, Leo wrote:
> 
> > Hello,
> >
> > I'm interested in added method name data in my logging messages, so
> I've
> > set up my RollingFileAppender like this:
> >
> > 	<appender name="File - Support"
> > type="log4net.Appender.RollingFileAppender">
> > 	  <param name="File"
> > value="c:\\LogFiles\\ReferenceApp\\ReferenceApp" />
> > 	  <param name="AppendToFile" value="true" />
> > 	  <param name="DatePattern" value="  - yyyy-MM-dd.'log'" />
> > 	  <param name="RollingStyle" value="Date" />
> > 	  <param name="StaticLogFileName" value="false" />
> > 	  <layout type="log4net.Layout.PatternLayout">
> > 	   <param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd
> > HH:mm:ss, fff} | %t | %c | %M | %t | %m%n" />
> > 	  </layout>
> > 	 </appender>
> >
> > %M tells Log4Net to output the name of the method within which the
> > logging statement was generated.
> >
> > Now, I have Ceki Culcu's book for log4j (I was a Java developer in
> a
> > previous life).  Within that he states:
> >
> > 	On certain platforms, generating the caller class information
> > can be excruciatingly slow.  Thus, the user of the C, F, l, L, and
> M
> > conversion characters should be avoided unless execution speed is
> not an
> > issue.
> >
> > My question is, given that I'm using Log4Net (1.2.8b) and not Log4J
> and
> > my platform is .NET 1.1, is this statement still true?  And if so,
> does
> > anyone have any benchmarks indicating how much of a performance
> penalty
> > will be taken for using the %M character?
> >
> > Thanks,
> > Leo Hart
> >
> 
> -- 
> Niall Daley
> Log4net Dev
> 


Re: Using %C, %F, %l, %L and %M in ConversionPattern

Posted by DW...@strohlsystems.com.
Niall,

Why do you generate an exception to get the stack trace?  You can generate
the stack trace much faster without the exception, either for the current
thread or (if needed) the calling thread.

David


                                                                           
             Niall Daley                                                   
             <niall@apache.org                                             
             >                                                          To 
                                       Log4NET User                        
             07/14/2005 03:45          <lo...@logging.apache.org>   
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: Using %C, %F, %l, %L and %M in  
              "Log4NET User"           ConversionPattern                   
             <log4net-user@log                                             
             ging.apache.org>                                              
                                                                           
                                                                           
                                                                           
                                                                           




Leo,
             In order to generate the method name log4net has to throw an
exception and check the stack trace so, yes, it is very much slower than
not doing so. As a rough guide line, on my machine it takes approximately
0.5 seconds to log 10000 messages with out %M and 6.4 seconds with it in
the pattern. If you really want to use this you should evaluate the
performance penalty in your own environment however.

                         Niall

On Thu, 14 Jul 2005, Hart, Leo wrote:

> Hello,
>
> I'm interested in added method name data in my logging messages, so I've
> set up my RollingFileAppender like this:
>
>            <appender name="File - Support"
> type="log4net.Appender.RollingFileAppender">
>              <param name="File"
> value="c:\\LogFiles\\ReferenceApp\\ReferenceApp" />
>              <param name="AppendToFile" value="true" />
>              <param name="DatePattern" value="  - yyyy-MM-dd.'log'" />
>              <param name="RollingStyle" value="Date" />
>              <param name="StaticLogFileName" value="false" />
>              <layout type="log4net.Layout.PatternLayout">
>               <param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd
> HH:mm:ss, fff} | %t | %c | %M | %t | %m%n" />
>              </layout>
>             </appender>
>
> %M tells Log4Net to output the name of the method within which the
> logging statement was generated.
>
> Now, I have Ceki Culcu's book for log4j (I was a Java developer in a
> previous life).  Within that he states:
>
>            On certain platforms, generating the caller class information
> can be excruciatingly slow.  Thus, the user of the C, F, l, L, and M
> conversion characters should be avoided unless execution speed is not an
> issue.
>
> My question is, given that I'm using Log4Net (1.2.8b) and not Log4J and
> my platform is .NET 1.1, is this statement still true?  And if so, does
> anyone have any benchmarks indicating how much of a performance penalty
> will be taken for using the %M character?
>
> Thanks,
> Leo Hart
>

--
Niall Daley
Log4net Dev



Re: Using %C, %F, %l, %L and %M in ConversionPattern

Posted by Niall Daley <ni...@apache.org>.
Leo,
	In order to generate the method name log4net has to throw an
exception and check the stack trace so, yes, it is very much slower than
not doing so. As a rough guide line, on my machine it takes approximately
0.5 seconds to log 10000 messages with out %M and 6.4 seconds with it in
the pattern. If you really want to use this you should evaluate the
performance penalty in your own environment however.

		Niall

On Thu, 14 Jul 2005, Hart, Leo wrote:

> Hello,
>
> I'm interested in added method name data in my logging messages, so I've
> set up my RollingFileAppender like this:
>
> 	<appender name="File - Support"
> type="log4net.Appender.RollingFileAppender">
> 	  <param name="File"
> value="c:\\LogFiles\\ReferenceApp\\ReferenceApp" />
> 	  <param name="AppendToFile" value="true" />
> 	  <param name="DatePattern" value="  - yyyy-MM-dd.'log'" />
> 	  <param name="RollingStyle" value="Date" />
> 	  <param name="StaticLogFileName" value="false" />
> 	  <layout type="log4net.Layout.PatternLayout">
> 	   <param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd
> HH:mm:ss, fff} | %t | %c | %M | %t | %m%n" />
> 	  </layout>
> 	 </appender>
>
> %M tells Log4Net to output the name of the method within which the
> logging statement was generated.
>
> Now, I have Ceki Culcu's book for log4j (I was a Java developer in a
> previous life).  Within that he states:
>
> 	On certain platforms, generating the caller class information
> can be excruciatingly slow.  Thus, the user of the C, F, l, L, and M
> conversion characters should be avoided unless execution speed is not an
> issue.
>
> My question is, given that I'm using Log4Net (1.2.8b) and not Log4J and
> my platform is .NET 1.1, is this statement still true?  And if so, does
> anyone have any benchmarks indicating how much of a performance penalty
> will be taken for using the %M character?
>
> Thanks,
> Leo Hart
>

-- 
Niall Daley
Log4net Dev