Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread Safety of log4net

Tags:

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?

like image 394
Alex Avatar asked Nov 04 '10 15:11

Alex


People also ask

Is log4net dependent on log4j?

Log4net is a logging utility for . NET applications. It's based on log4j, which is for Java applications. Log4net is highly configurable, so you can use it in many scenarios.

What is the use of log4net in C#?

Log4net provides a simple mechanism for logging information to a variety of sources. Information is logged via one or more loggers. These loggers are provided at the below levels of logging: Debug.


1 Answers

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:

lock(logger) {   logger.Info("Hello!"); } 
like image 154
wageoghe Avatar answered Oct 01 '22 13:10

wageoghe