Troubleshooting With Log4net RollingFileAppender

Be wise when providing your settings for RollingFileAppender of log4net. You may miss some entries due to your settings specified and land you in trouble when troubleshooting because no information would be available to you.

This article is about troubleshooting and not a how-to. Earlier, a friend of mine was testing a ftp file upload application. One of his problems was a struggle to verify the FTP uploaded files against the local machine and he landed with the following awesome findings:

  • There was a text file that was not logged in logs but has been transferred successfully
  • File size was different for text files
  • This size mismatch transfer is not a perfect transfer and should be in an Error log but it was not there

Let's cover our resolution approaches for all the above issues in a series of posts-

Why a specific text file entry was missing

His application uses log4net for logging with the RollingFileAppender configuration as:

  1. <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">  
  2.   <file value="InfoLog.txt" />  
  3.   <appendToFile value="true" />  
  4.   <rollingStyle value="Size" />  
  5.   <maxSizeRollBackups value="10" />  
  6.   <maximumFileSize value="2MB" />  
  7.   <staticLogFileName value="true" />  
  8.   <layout type="log4net.Layout.PatternLayout">  
  9.     <conversionPattern value="%date [%thread] %level %logger - %message%newline" />  
  10.   </layout>  
  11. </appender>  
In his verification, he found a text file with an entry that was not present in any log files. I asked him to do the following 2 exercises to confirm whether it is log4net partiality for text files. :)
  • Is it only happening for that particular text file or all text files or with any file type?
  • Have you checked by transferring only that file (single file transfer)?

He was in such hurry and tense to not do any further drill down. He affirmed with his findings without listening to the facts. This happens to anyone if you are running behind the schedules and are lacking time. I asked for these 2 exercises because I saw him in such a panic and ditto that he is missing something. Log4net can't play revenge with a specific text file by avoiding its logging :P but, he was so confident to not listen to me for this basic troubleshooting procedure.

Troubleshooting ideas

Increase the no Roll Backup nos. to a higher one:

  1. <maxSizeRollBackups value="100" />  

OR

Increase the file size:

  1. <maximumFileSize value="10MB" />  

OR

Check by just transferring only that specific text file to see if it is being logged.

Cause / Finding(s)

It was as obvious as I guessed, there was nothing ignored. RollingFileAppender was set to keep only 10 log files of 2Mb of each. In this case, only 10 log files entries are maintained and other files are deleted by the logger. And that specific file was the victim of this. In other words, there may be other files whose log information was disappearing from the log files.

Let's troubleshoot the 2 remaining issues in the next article Smile:) Continue...

Twitter: @AnilAwadh

Up Next
    Ebook Download
    View all
    Learn
    View all