Tourbleshooting with log4net RollingFileAppender

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

This post is about troubleshooting and not a how-to. One of my known was struggling to verify ftp uploaded files against the local machine and he landed with his following awesome findings-

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

Hmm, Let’s start our troubleshoot starting from the last one.

Why a particular text file entry was missing ?

His application uses log4net for logging with 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 which entry was not present in any log files. I asked him to do following 2 exercises to get confirm if it is log4net partiality for text files. :)

  • Is it only happening for this 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 so hurry-bury and tensed to not do any further drill down. He affirmed with his findings without listening the facts. This happens to anyone if you are running behind the schedules and lacking of time. I asked for these 2 exercises because I saw him in hurry-burry and ditto that he is missing something. Log4net can’t play revenge with a particular text file by avoiding its logging :P but, he was so confident to not listen me for these basic troubleshooting steps.

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 particular text file to see if it is being logged.

Cause / Finding(s)

It 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 get deleted by logger. And that particular file was the victim of this. It means there may be other files whose log information was going vanish with log files.


Let’s continue troubleshooting of 2 left issues in next post File Size mismatch on FTP and local machine