I have a strange problem. I'm trying to create multiple rolling file appenders referencing everyone the same file, but using only one of theese appenders at a time.
The matter is, if i declare my appender like this:
<appender name="APP1" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log.txt" />
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - message%newline" />
</layout>
</appender>
<logger name="APP1" additivity="false">
<level value="DEBUG" />
<appender-ref ref="APP1" />
</logger>
<appender name="APP2" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log.txt" />
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - message%newline" />
</layout>
</appender>
<logger name="APP2" additivity="false">
<level value="DEBUG" />
<appender-ref ref="APP2" />
</logger>
Then my "APP1" logger writes to the file with no problem, but not the "APP2" logger, like if it's obtaining only the first logger. Obviously, if i make the two logger switch place, everything works for "APP2", but not for "APP1"
Also, when the appending fails i can see this in the debug window:
log4net: Opening file for writing [C:\Log.txt] append [True]
log4net: Opening file for writing [C:\Log.txt] append [True]
Which, i guess, it means it is appending, but strangely enough it doesn't do so. And in the working scenario I cannot see those logs. Any hint is greatly appreciated!! Thanks for your time
Maybe you can write it like this:
Here is a configuration file that uses multiple appenders. You can find it in http://logging.apache.org/log4net/release/manual/configuration.html
It's possible that uses multiple appenders, but you can't use multiple FileAppenders(or RollingFileAppenders) to log in the same file. So if you change the APP2 appender to log in a different file, it works.
The problem maybe log4net can't access same file at same time by different FileAppenders.