有人有这两方面的经验吗?它们之间有什么不同?
我们计划使用其中一个来登录企业应用程序。
引用:
log4net
nlog
编辑:我们对nlog或log4net没有现有的依赖关系。
有人有这两方面的经验吗?它们之间有什么不同?
我们计划使用其中一个来登录企业应用程序。
引用:
log4net
nlog
编辑:我们对nlog或log4net没有现有的依赖关系。
当前回答
我认为一般的共识是nlog更容易配置和使用。不过,两者都很有能力。
其他回答
根据我的经验,SmartInspect优于NLog和log4net。
它非常容易使用,文档很棒,您可以使用交互式日志查看器查看和过滤以前记录的消息,这是一个巨大的现实优势。
我喜欢的一件事是数据的标签视图,就像Chrome中的浏览器标签。每个选项卡都可以提供不同的日志过滤视图。
一个没有被过多讨论的关键考虑因素是支持和更新。
Log4Net自2006年4月19日发布1.2.10版本以来就没有更新过。
相比之下,NLog自2006年以来一直被积极支持,不久将发布NLog 2.0,支持许多在log4net上次更新时还不存在的平台,例如:
NET Framework 2.0 SP1及以上版本,3.5 & 4.0(客户端和扩展配置文件) Silverlight 2.0, 3.0, 4.0 .NET紧凑框架2.0,3.5 Mono 2。x档案
对我们来说,关键的区别在于整体表现……
看看Logger。与Log4Net相比,NLog中的IsDebugEnabled,从我们的测试来看,NLog的开销更少,这就是我们所追求的(低延迟的东西)。
干杯, 弗洛里安
由于最近使用过这两个框架,我想我可以分享一下我对这两个框架的看法。
我被要求评估现有web应用程序的日志框架,在浏览了各种在线论坛后,我将选择范围缩小到NLog (v2.0)和log4net (v1.2.11)。以下是我的发现:
Setting/starting up with NLog is dead easy. You go through the Getting started tutorial on their website and you are done. You get a fair idea, how thing might be with nlog. Config file is so intuitive that anyone can understand the config. For example: if you want to set the internal logging on, you set the flag in Nlog config file's header node, which is where you would expect it to be. In log4net, you set different flags in web.config's appSettings section. In log4net, internal logging doesnt output timestamp which is annoying. In Nlog, you get a nice log with timestamps. I found it very useful in my evaluations. Filters in log4net - You better check my this question - log4net filter - how to write AND filter to ignore log messages and if you find an answer/solution for this, please let me know. I understand, there is a workaround for this question, as you can write your own custom filter. But something which is not easily available in log4net. Performance - I logged around 3000 log messages to database using a stored procedure. I used simple for loop (int i=0; i<3000; i++... to log the same message 3000 times. For the writes: log4net AdoAppender took almost double the time than NLog. Log4net doesnt support asynchronous appender.
经过比较,我选择了NLog作为日志框架。:)
我最近被要求为一个即将到来的项目“创建一些登录的原型”。我没有任何日志框架的经验。我花了几天时间在Log4Net、NLog和Enterprise Library上研究、浏览教程、制作玩具应用程序等。3-4周后再回来,将它们整合成一个完整的演示版本。希望这些对你们有用。
我对我们项目的建议是:
使用日志facade(例如Common。日志,SimpleLoggingFacade)以避免直接依赖。 如果我们最终要将企业库用于其他功能,那么也要将其用于日志记录。 如果我们最终要使用依赖于Log4Net的东西,那么就使用Log4Net。 如果以上都不是,请使用NLog。我更喜欢这样。
这是基于以下发现(意见!):
All 3 frameworks are capable and can do some sophisticated things. We want a quality solution, but frankly don't need ultra high performance or 60 types of event sinks. All 3 have very similar basic concepts. Each has its own cool tricks, like really advanced routing, or dynamic log filenames, file truncating, etc. All 3 are pretty well documented in their own way. For a complete newb like me, they were all a little awkward initially. No drastic differences here for the basics. I got over it. When revisiting things a few weeks later, NLog was clearly the easiest to resume. I needed very little brush up on it. With Log4Net, I had to revisit a few online examples to get going. With EntLib, I gave up and did the tutorials all over again from scratch - I was totally lost. I couldn't figure out how to get EntLib to do some things like log to the database. It might be easy, but it was beyond my time limit. Log4Net and NLog have a small in-code footprint. EntLib is spammy, but I'd use a facade over it anyway. I accidentally mis-configured EntLib and it told me at run time. Log4Net didn't. I didn't have an accidental mis-config with NLog. EntLib comes with a nice looking app.config editor, which you 100% need. NLog has a config file schema so you get "intellisense". Log4Net comes with nada.
显然到目前为止我喜欢NLog。尽管有其他可用的解决方案,但还不足以使用它。