I have a client-side application that uses log4net's RollingFileAppender and that can be instantiated multiple times. Initially I've written all my logs into a single file, however, I've realized soon enough that log4net locks the file while writing, though, even if I used a less restrictive writing mode, I would still end up with a lot of mess in my log files.
I've decided to incorporate process-id into the file name, like so:
<appender name="HumanRollingLog" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Log\TestLog[%processid].txt"/>
<param name="DatePattern" value="dd.MM.yyyy'.log'"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<staticLogFileName value="true" />
<maxSizeRollBackups value="10"/>
<maximumFileSize value="1KB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%type] [%thread] %-5level %logger - %message%newline%exception%"/>
</layout>
</appender>
That worked. However, it completely messed up the rolling features since now every process spawns its own log file, the actual rolling would happen only after process ids start repeating. E.g, starting my application 3 times resulting the following logs being created:
TestLog[5396].txt
TestLog[5396].txt.1
TestLog[5396].txt.10
TestLog[5396].txt.2
TestLog[5396].txt.3
TestLog[5396].txt.4
TestLog[5396].txt.5
TestLog[5396].txt.6
TestLog[5396].txt.7
TestLog[5396].txt.8
TestLog[5396].txt.9
TestLog[5976].txt
TestLog[5976].txt.1
TestLog[5976].txt.10
TestLog[5976].txt.2
TestLog[5976].txt.3
TestLog[5976].txt.4
TestLog[5976].txt.5
TestLog[5976].txt.6
TestLog[5976].txt.7
TestLog[5976].txt.8
TestLog[5976].txt.9
TestLog[6860].txt
TestLog[6860].txt.1
TestLog[6860].txt.10
TestLog[6860].txt.2
TestLog[6860].txt.3
TestLog[6860].txt.4
TestLog[6860].txt.5
TestLog[6860].txt.6
TestLog[6860].txt.7
TestLog[6860].txt.8
TestLog[6860].txt.9
Anyone has an idea what can I do to resolve this issue? I'd like to have each process its own file, but I can't allow the rolling to be reused among ALL the processes.
Thanks!