4 Replies Latest reply on Sep 5, 2017 10:08 AM by gir489

    Log4J Failed to rename [logs/CacheClearance.log] to [logs/CacheClearance.log.2017-08-31].

    gir489 Newbie

      I'm currently trying to fix an issue a Wildfly 10 integration issue that happens in the morning when the first call to a static class called ClearCache happens. (This was working fine on JBoss 4)

       

      The appender is currently using DailyRollingFileAppender and a simple category for CacheCheck that we send to our Logger static class that calls loggerRepository.getLogger(category).info(message);

       

      I googled the error and arrived here: 29726 – DailyRollingFileAppender : log4j:ERROR Failed to rename

       

      The people writing in the comments proclaim that the use of File.renameTo is the culprit, because of how it works on Windows. (We're on a Windows server, so this kind of makes sense, I guess?)

       

      After more googling, I arrived here: java - Reliable File.renameTo() alternative on Windows? - Stack Overflow

       

      I put a breakpoint on DailyRollingFileAppender right after it calls this.closeFile(); I then tried to verify that the lock was broken on CacheClearence.log, but Windows says that java.exe still has a handle to the file.

       

      I thought there was some inherent handle to the file from some kind of ghost module I wasn't seeing, so I restarted the server, verified the lock was broken, put a BP before I called ClearCache, lock was broken, called Logger.info("ChacheCheck", "Test"); Lock engaged. Stepped after this.closeFile(), lock still engaged.

       

      I have NO idea what's causing this. I tried porting to Log4J 2 to see if that would help, but Log4J 2 doesn't use categories, it goes by strict class enforcement, so I figured out real fast that wasn't going to work from a static Logger class, we'd have to refactor our 500+ Java files to have a static member Logger logger = Logger.getLogger(this.getClass()); Which would be a massive pain to do.