Previous filename in RollingFileAppender
I am using Log4Net for logging in an application I've written. For writing to the log file, I use a RollingFileAppender with 5 backups and a max filesize of 250KB.
What I want to do is offer the user an opportunity to send me the log if a crash occurs. I want this presented to the user as a possibility, if they start the program again.
The trouble is, though, the log file will 开发者_JAVA技巧usually perform a rollover when the program starts, due to apparently not rolling over during the program execution.
What I want is therefore the filename of the log file that was just rolled over, that is the previous log file.
Is there an easy way to find that?
I would say your best bet is to do a directory lookup on the location where your log files are stored. You know the pattern for the file, so you can narrow down the list of files to only log file types. Then find the newest file that has a number after the .txt. For example, if you log to log.txt, a rolled over log will be called log.txt.1 since the current log will always be log.txt. If you find the newest file, you will always know which file to send.
精彩评论