[jira] [Commented] (LOG4NET-552) Incorrect behavior of RollingFileAppender while rolling files, if multiple processes appending into same file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (LOG4NET-552) Incorrect behavior of RollingFileAppender while rolling files, if multiple processes appending into same file

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/LOG4NET-552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15942896#comment-15942896 ]

Sachin Abaso Patil commented on LOG4NET-552:

Hi Dominik,

We have made below changes into log4net source code of version 1.2.15 to resolve below mentioned two issues,

1. To resolve overwrite issue for time based rolling:- If file to be rolled with destination name is exists(some other process has rolled it already) then do not perform rolling.
2. To resolve issue where some log entries were missing:- During debugging log4net source code, we found that due to error “Unable to acquire lock on file C:\Log4Net_LogFiles\log.txt. The process cannot access the file 'C:\Log4Net_LogFiles\log.txt' because it is being used by another process”, acquire lock during append operation was failing thus was skipping writing log. Here we thought of below solution. We implemented and tested the solution.
a. Solution1 – Using Mutex: Here we have protected AcquireLock method using system wide Mutex. And once append is done, we are releasing Mutex in ReleaseLock method. This change is made only in minimal lock model to protect append operation.

During this test, total 15 processes were writing into same file simultaneously with frequency of 100ms for 15 minutes. Total 1,02,215 log entries were written and only one was skipped. No file overwrite issue happened.

@Dominik, do you think any possible side effect of above change except performance? If you want we can share code screen shot for your review.

Sachin Patil

> Incorrect behavior of RollingFileAppender while rolling files, if multiple processes appending into same file
> -------------------------------------------------------------------------------------------------------------
>                 Key: LOG4NET-552
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-552
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 1.2.15
>         Environment: Windows Server 2008 R2 Enterprise
>            Reporter: Sachin Abaso Patil
>            Priority: Blocker
>         Attachments: Modification in AdjustFileBeforeAppend.png
> Hi Team,
> This issue has become blocker for us, as on our production environment, multiple processes are appending log into single log file which has no issue, but while rolling it overwrites files and thus missing log entries.
> Based on link below, it looks like log file rolling mechanism of log4net is not process safe even after using FileAppender.InterProcessLock.
> Link: https://issues.apache.org/jira/browse/LOG4NET-485
> Also, in FAQ (https://logging.apache.org/log4net/release/faq.html) under section “How do I get multiple process to log to the same file?”, it has been clearly mentioned that, rolling files is simply not compatible with multiple process scenario.
> My questions,
> 1. We are using version “1.2.15”. Are you planning to fix above mentioned rolling issue in upcoming release? If yes then please provide tentative release date.
> 2. We had incorporated log4net in our project in year 2009, had FAQ mentioned this limitation (rolling file not compatible with multi process) in year 2009? Because we while studying log4net during year 2009 we do not remember seeing this note in FAQ?
> Requesting you to please respond as soon as possible with your comments.
> Below is how we have configured appender for all processes,
>     <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
>     <threshold value ="ERROR"/>
>     <file value="${SystemDrive}\LogFiles\Example.log" />
>     <param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
>     <appendToFile value="true" />
>     <maximumFileSize value="100MB" />
>     <staticLogFileName value="true"/>
>     <maxSizeRollBackups value="-1" />
>     <countDirection value="1" />
>     <datePattern value=".yyyyMMddHH'.log'"/>
>     <rollingStyle value="Composite" />
>     <ignoreExceptionItemAgeLimit value="false" />
>     <exceptionItemAgeLimit value="00:00:59" />
>     <layout type="log4net.Layout.PatternLayout">
>       <param name="conversionPattern" value ="%utcdate{yyyy-MM-dd HH:mm:ss.fff}|%-5level|%property{EventID}|%property{log4net:HostName}|%appdomain|%property{ProcessID}|%thread|%message%newline"/>
>     </layout>
>   </appender>
> Thanks,
> Sachin Patil

This message was sent by Atlassian JIRA