Thread Safety of log4net

There seems to be some discussion on whether log4net is thread-safe, the consensus is that the framework is thread-safe, but appenders are not and need to be used correctly to achieve thread-safety. can someone shine some light on this and possibly give example of lets say RollingFileAppender used in a thread-safe way? does it need to be pushed into context? somehow locked, or what?


According to this link, RollingFileAppender is thread safe (as far as logging is concerned). This is coming from one of the developers of log4net. He specifically says that locking like this is not required in your code:


Straight from the log4net FAQ:

Is log4net thread-safe?

Yes, log4net is thread-safe.

So, no need for manual locking.

But I've had a deadlock with ColoredConsoleAppender. And it sources comment states that internal writer (m_consoleOutputWriter) is not thread safe!

/// <summary>
/// The console output stream writer to write to
/// </summary>
/// <remarks>
/// <para>
/// This writer is not thread safe.
/// </para>
/// </remarks>
private System.IO.StreamWriter m_consoleOutputWriter = null;

And I've switched back to basic ConsoleAppender and have no issues since then.

Need Your Help

How to filter logcat in Android Studio?

android-studio logcat

In my logcat there is too much output, so I'd like to filter it using some keywords, basically displaying only the output containing the keyword(s). Is there a way to do that in Android Studio thro...

How to show user-friendly error page in browser when runtime exception is thrown by servlet?

jsp jsf facelets custom-error-pages

I'm developing web-application with JSF. I tested it as I was able to but from time to time runtime exceptions are thrown.