Daily log4net appender

Wednesday, March 21, 2012 0 Comments

One of our more interesting server logs is the "ChannelCall" logger. It gives you a full detailed information about all the server requests. If you set it to DEBUG you will be able to check the following data for each incoming client call:

  • Bytes received.
  • Time to receive the message.
  • Bytes sent.
  • Time to execute the operation invoked (ms)
  • Operation invoqued.
  • Client machine IP.
  • Thread to attend the call.

This is an example of how it looks like:

2012-03-16 14:43:16,783   INFO  ChannelCall - |1638|0|2051|0| proc 47 | ExecuteSimpleQuery | 127.0.0.1 | 13

It's very useful to determine if a call is taking too much time to execute an operation and diagnose performance problems. For example, a log entry with a proc time like this proc 1200000 creating a branch obviously is not a good time, unless you are using Perforce.

The problem with this kind of log is that if your company has a big number of developers. Let's say 500, the number of incoming calls is going to be huge and the log file is going to grow and grow without control, you will find yourself dealing with a 3GB text file... A 3GB file is almost unmanageable and it's hard to find something relevant inside it. I want to show you how to configure a log4net appender that will generate a log file everyday, smaller, simpler, and it's obviously categorized by day.

...
<appender name="ChannelCallDailyFileAppender" type="log4net.Appender.RollingFileAppender">
    <lockingmodel type="log4net.Appender.FileAppender"/>
    <file value="ChannelCall.log." />
    <appendtofile value="true" />
    <staticlogfilename value="false" />
    <rollingstyle value="Date" />
    <datepattern value="yyyy.MM.dd-HH.mm'.txt'" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionpattern value="%date  %-5level %logger - %message%newline" />
    </layout>
</appender>
...

Note that this appender creates, if the program is generating log info constantly, a new log file every minute, you can must change it to diary mode with this date pattern: "yyyy.MM.dd". Otherwise we will have a crazy bunch of little log files. This is only an example to show you how the log files are created without having to wait one hour to see the result.

Let's use our brand new daily channel call log appender:

...
<logger name="ChannelCall">
        <level value="DEBUG" />
        <appender-ref ref="ChannelCallDailyFileAppender" />
</logger>
...

You can user the new appender and logger inside your "loader.log.conf" file inside the Plastic SCM server installation directory. Here you can find more information about the Plastic SCM log.

Enjoy!



0 comentarios: