Log4net “it is being used by another process” Problem

If you use log4net for logging and try to download log files from the server, sometimes “file is being used” problem occurs. There is a configuration for minimal locking the log file.

<log4net>
<appender…
<lockingModel type=”log4net.Appender.FileAppender+MinimalLock” />
</appender>
</log4net>

 There is some performance impact because this means that log4net will lock the file, write to it, and unlock it for each write operation.

If you use RollingFileAppender things become even worse as several process may try to start rolling the log file concurrently. RollingFileAppender completely ignores the locking model when rolling files, rolling files is simply not compatible with this scenario.

Read more...