Menu

#296 When logging from exe and dll to same log file, rolling file appender failes to rename file

v1.1.2
open
5
2014-08-17
2014-02-19
Darius
No

log4cplus configuration:

  • VS2010
  • Debug/Release
  • Windows 7 64bit
  • x64/win32
  • DLL version/static version
  • RollingFileAppender

How to reproduce:

  1. Create exe.
  2. Create separate dll and link it to exe.
  3. Configure loggers (RollingFileAppender) in dll and exe to use same log file.
  4. At this point when file needs to be rolled over, error 13 is returned.

Workaround:

  1. Use DLL version of log4cplus.
  2. Add "log4cplus.appender.<logger name="">.UseLockFile=true".
  3. At this point RollingFileAppender works as expected.

Discussion

  • Václav Haisman

    Václav Haisman - 2014-03-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,18 +1,21 @@
     log4cplus configuration:
    -VS2010
    -Debug/Release
    -Windows 7 64bit
    -x64/win32
    -DLL version/static version
    -RollingFileAppender
    +
    +* VS2010
    +* Debug/Release
    +* Windows 7 64bit
    +* x64/win32
    +* DLL version/static version
    +* RollingFileAppender
    
     How to reproduce:
    +
     1. Create exe.
     2. Create separate dll and link it to exe.
     3. Configure loggers (RollingFileAppender) in dll and exe to use same log file.
     4. At this point when file needs to be rolled over, error 13 is returned.
    
     Workaround:
    +
     1. Use DLL version of log4cplus.
     2. Add "log4cplus.appender.<logger name>.UseLockFile=true".
     3. At this point RollingFileAppender works as expected.
    
     
  • Václav Haisman

    Václav Haisman - 2014-03-07

    You probably should never have two appenders opening the same file in the first place. You can have a single appender attached to multiple loggers. Doing that, using a single appender for multiple loggers, will fix the problem.

    The core of the problem is that the files opened by std::fstream are not opened by the Visual Studio C++ standard library implementation in a way that would allow renaming (or deletion) while there are open handles to the file. This is not easy to fix or work around in any other way than outlined above.

     
  • Václav Haisman

    Václav Haisman - 2014-03-07
    • labels: --> rollingfileappender, win32, windows, msvc
    • assigned_to: Václav Zeman
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.