Log4View interfers with Log4Net file rolling causing loss of log data

Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Log4View interfers with Log4Net file rolling causing loss of log data

WDiTVnJK
Hi,

I have an appliation that uses Log4Net with an XML file appender using minimal locking and file rolling. File rolling is configured to roll when the file reaches a certain size.

The file rolling behaves the following way:
Logging starts with writing to a file Log.xml. If the file becomes too big, it is renamed to Log.1.xml and logging continues for a newly created Log.xml. If that files reaches the size limit, then the previous files are renamed again (Log.1.xml => Log.2.xml, Log.xml => Log.1.xml). Renaming the prevois files continues until the maximum number of rolled files N is reached, which results in the Log.<N>.xml to be deleted.

This file rolling works flawlessly when Log4View is not running. However, if Log.xml and Log.*.xml are open in Log4View then file rolling causes the logging process to fail zo log additional log entries as long as Log4view stays opened.

If you want, I can provide a minmal example for the logging behavior of the application, so you can reproduce the issue more easily.
Reply | Threaded
Open this post in threaded view
|

Re: Log4View interfers with Log4Net file rolling causing loss of log data

Ulrich
Administrator
The scenario of having Log4View open while logging occurs via log4net to a rolling file appender is one of the key use cases and we have done quite some effort to guarantee that this case is working flawlessly.

We use the following log4net rolling file appender configuration to test this case:

<appender name="FileAppenderXml" type="log4net.Appender.RollingFileAppender" >
    <file value="Logoutput\LogEmiter.xlog"/>
    <appendToFile value="true"/>
    <rollingStyle value="Size"/>
    <maxSizeRollBackups value="199"/>
    <maximumFileSize value="10MB"/>
    <staticLogFileName value="true"/>
    <preserveLogFileNameExtension value="true"/>
    <layout type="log4net.Layout.XmlLayout">
      <locationInfo value="false"/>
      <prefix value="" />
    </layout>
</appender>

If this doesn't work in your case with the latest release of Log4View, please send your Log4View configuration file (*.lvc).
Reply | Threaded
Open this post in threaded view
|

Re: Log4View interfers with Log4Net file rolling causing loss of log data

WDiTVnJK
Sorry for the delay,

using your recommended appender configuration was not successful. If I open the log file (including the rolled files) in Log4View, while the application is writing to it, I will get an exception in the application when file rolling is triggered during logging.

I prepared a small console application that reproduces the problem. The app will first log some data, so that the maximum allowed rolling log files are created. It then pauses for the user to open the log file in Log4View. If you open the file in Log4View (with the option to read rolled files enabled) and then continue the app, log4net will throw an exception, because the file rolling encountered a locked file.

Log4ViewTester.zip