log4net的的线程安全 [英] Thread Safety of log4net

查看:180
本文介绍了log4net的的线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们似乎对log4net的是否是线程安全的一些讨论,一致认为该框架是线程安全的,但附加目的地不是,需要正确的使用来实现线程安全。有人可以发光一些轻就这个问题和可能给予的例子可以说RollingFileAppender进行使用一个线程安全的方式?它需要推入背景?不知何故被锁定,还是什么?

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?

推荐答案

根据这个<一个href="http://www.l4ndash.com/Log4NetMailArchive%2Ftabid%2F70%2Fforumid%2F1%2Fpostid%2F17279%2Fview%2Ftopic%2FDefault.aspx">link, RollingFileAppender进行是线程安全的(就记录而言)。这是从log4net的的开发者之一到来。他特别指出,锁定像这样不需要在code:

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!");
}

这篇关于log4net的的线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆