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:
- <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
- <file value="InfoLog.txt" />
- <appendToFile value="true" />
- <rollingStyle value="Size" />
- <maxSizeRollBackups value="10" />
- <maximumFileSize value="2MB" />
- <staticLogFileName value="true" />
- <layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
- </layout>
- </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:
- <maxSizeRollBackups value="100" />
OR
Increase the file size:
- <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 :) Continue...