什么时候应该使用跟踪VS Logger.NET,企业库,log4net的或Ukadc.Diagnostics? [英] When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

查看:282
本文介绍了什么时候应该使用跟踪VS Logger.NET,企业库,log4net的或Ukadc.Diagnostics?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择之间标准的跟踪,Logger.NET,企业库,log4net的或Ukadc.Diagnostics?

How do I choose between standard tracing, Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

有一种情况,其中一个比另一个更合适? ......那会是什么? (ASP.NET,控制台应用程序,Azure云,SOHO,企业...)

Is there a situation where one is more appropriate than the other? ... what would that be? (ASP.NET, console app, Azure Cloud, SOHO, Enterprise...)

有什么好处还是缺点?

我错过任何其他主要的日志框架?

Did I miss any other major logging frameworks?

推荐答案

有很多类似的问题在这里SO:

There are many similar questions here on SO:

  • Logging best practices
  • log4net versus TraceSource
  • Silverlight Logging framework and/or best practices
  • log4net vs. Nlog
  • What's the point of a logging facade?
  • C# Logging. What should I use?

您错过了几个常用的日志框架。这里是常用的框架,其中一些你列出的列表:

You missed several commonly used logging frameworks. Here is a list of commonly used frameworks, some of which you listed:

  • System.Diagnostics
  • log4net
  • NLog
  • Enterprise Library
  • The Object Guy

日志抽象:

  • Common.Logging
  • SLF

System.Diagnostics程序插件:

System.Diagnostics addons:

  • Ukadc.Dianostics
  • Essential.Diagnostics

其他

一对夫妇从codePLEX其他日志框架(我已经看到这里提到的SO):

A couple of other logging frameworks from codeplex (that I have seen mentioned here on SO):

  • CuttingEdge.Logging
  • SpringTail

为什么你会选择一个比其他?这是一个艰难的一个。很多是个人preference。有些是技术性(或要素)的优势。

Why you might choose one over the other? That's a tough one. A lot of it is personal preference. Some of it is technical (or feature) superiority.

中的任何日志框架(尤其是第三方的)的一个明显缺点是支持的质量。如果你有一个问题,log4net的,NLOG,Common.Logging等?你将能够从这些框架的开发者解决?这可能不是极其重要的来源$ C ​​$ C适用于这些框架。但是,您可能preFER不要继承的源代码树只是为了修复或添加增强。我会说,框架是使可扩展的,许多增强功能可通过正常的扩展点被添加。

One obvious drawback of any logging framework (particularly third party ones) is the quality of support. What if you have an issue with log4net, NLog, Common.Logging, etc? Will you be able to get a fix from the developers of those frameworks? This might not be tremendously important as the source code is available for these frameworks. However, you might prefer NOT to "inherit" the source tree just to make a fix or add an enhancement. I will say that the frameworks are so extensible, that many enhancements could be added via normal extension points.

如果你看了我上面贴的链接,我认为这是公平地说,仅仅根据有利提到,这log4net的将是明确的赢家的音量。这将是更经常提到的历史记录的最爱,很多人会选择使用向前发展。

If you read the links that I posted above, I think that it is fair to say, based solely on the volume of favorable mentions, that log4net would be the clear "winner". It will be mentioned more frequently as the historical logging favorite and what many people would choose to use going forward.

NLOG有它的支持者,它只是似乎并不具备穿透力,或首要考虑认识到log4net的存在,即使他们是非常相似的。 NLOG的能力非常相似log4net的,它具有通过显著开发周期在经历最近的额外优势。

NLog has its supporters, it just doesn't seem to have the penetration, or "top of mind" awareness that log4net does, even though they are very similar. NLog's capabilities are very similar to log4net and it has the extra advantage of having gone through a significant development cycle recently.

企业库往往被吹捧为一个不错的选择,但几乎同样经常被吹捧为一个可怕的选择。也许它的一些负面的名声是也许不那么良好的早期版本?也许这是好些了吗?

Enterprise Library is often touted as a good choice, but is almost equally as often touted as a terrible choice. Maybe some of its negative reputation is maybe not so good early versions? Maybe it is better now?

System.Diagnostics程序经常被推荐作为一个合理的选择,至少三强的好处:没有第三方的依赖,许多微软组件仪表与System.Diagnostics程序,它很容易扩展(presumably补充说,有一些功能已经$像log4net的和NLOG框架p $ psent免费?)。如果你使用System.Diagnostics程序,我想达成的共识将是(如将我recommenation)使用TraceSource对象,而不是Trace.WriteLine /的Debug.WriteLine。

System.Diagnostics is often recommended as a reasonable choice with at least three strong benefits: no third party dependency, many Microsoft components are instrumented with System.Diagnostics, it is easily extendable (presumably to add some capabilities that are already present "for free" in frameworks like log4net and NLog?). If you use System.Diagnostics, I think the consensus would be (as would my recommenation) to use TraceSource objects rather than Trace.WriteLine/Debug.WriteLine.

还要注意System.Diagnostics程序和WCF很好地协同工作。 WCF消息流量可以被记录与System.Diagnostics程序和WCF也将传播System.Diagnostics程序活动信息(System.Diagnostics.CorrelationManager.ActivityId)跨WCF服务边界的电话。

Note also that System.Diagnostics and WCF work well together. WCF message traffic can be logged with System.Diagnostics and WCF will also propagate System.Diagnostics activity information (System.Diagnostics.CorrelationManager.ActivityId) across WCF service boundary calls.

我不那么肯定log4net的应当继续保留其最受宠的地位。 由于已经注意到其他地方在这里SO,log4net的似乎并没有经历一次很大的发展最近(请注意,我认为log4net的死是一个夸张),而NLOG 2.0是目前在测试与最终版本预计将在2011年第一季度(更新:NLOG 2.0的已于2011年7月17日)公布。这是否让NLOG一个比log4net的明显更好的选择?我不知道,但我认为,相对而言,NLOG应该得到两个之间进行选择时,至少同等的考虑,可能,应该是presumed最喜欢的新的发展,至少要等到log4net的发展呈现出多迹象的生活。

I'm not so sure that log4net should continue to retain its most favored status. As has been noted elsewhere here on SO, log4net does not seem to be undergoing a lot of development recently (note that I think "log4net is dead" is an exaggeration) while NLog 2.0 is currently out in beta with final release expected in Q1 2011 (Update: NLog 2.0 was released on Jul 17, 2011). Does this make NLog an obviously better choice than log4net? I don't know, but I think that, relatively speaking, NLog should receive at least equal consideration when choosing between the two and, probably, should be the presumed favorite for new development, at least until log4net development shows more signs of life.

log4net的和NLOG都提供了非常灵活的配置选项。他们让你有很细的粒度在你的日志报表的定义(定义每种类型的记录程序的标准模式)。他们还允许容易扩展库通过允许你开发自己的日志目的对象(log4net的附加目的地和NLOG目标)和格式化的对象(log4net的模式转换器和NLOG LayoutRenderers)。

log4net and NLog both offer very flexible configuration options. They allow you to have very fine granularity in the definition of your logging statements (by the "standard" pattern of defining a logger per type). They also allow for easy extension of the libraries by allow you to develop your own "logging destination" objects (log4net Appenders and NLog Targets) and "formatting" objects (log4net pattern converters and NLog LayoutRenderers).

除了日志框架的选择,通过使用一个抽象层绝缘您的应用程序code从硬依赖于特定的日志框架一些(很多?)倡导者。这可能需要你实现,也许在现有的框架顶部自己ILogger接口的形式。在未来,你可以通过实现ILogger通过不同的架构改变的框架。或者,你可以使用DI / IoC容器的注入ILogger到code。许多DI / IoC框架上提供了一个内置的ILogger抽象,可以配置为使用log4net的,NLOG,或企业库,或者你可以写自己ILogger实现,并注入了)。谁在乎的实现是什么?另一种方法是从一个特定的日志框架有一个很难依赖隔离你的code是通过利用现有的日志抽象的框架,如Common.Logging或SLF。这样做的好处是,再次,应用程序不依赖于特定的日志框架。然而,有些人会说,你刚换一个依赖(在记录framwork)的另一(日志抽象框架)。

Aside from a logging framework choice, some (many?) advocate for insulating your application code from a hard dependency on a particular logging framework by use of an abstraction layer. This can take the form of your own ILogger interface that you implement, perhaps on top of an existing framework. In the future, you could change frameworks by implementing your ILogger over a different framework. Or, you could use DI/IoC to inject "ILogger" into your code. Many DI/IoC frameworks provide a built-in ILogger abstraction that can be configured to use log4net, NLog, or Enterprise Library or you could write your own ILogger implementation and inject that). Who cares what the implementation is? Another way to insulate your code from having a hard dependency on a specific logging framework is through the use of an existing logging abstraction framework such as Common.Logging or SLF. The benefit is that, again, your application is not dependent on a specific logging framework. However, some would say that you have just traded one dependency (on a logging framwork) for another (logging abstraction framework).

有关日志抽象还有两个注意事项:

Two more notes about logging abstraction:

  1. 一个很好的日志抽象应该让你捕捉来自不同的日志框架输出在同一个输出文件。 Common.Logging称此为桥梁。说你已经写了使用Common.Logging一个应用程序,通过NLOG支持。现在说你正在使用使用log4net的是直接写第三方类库。通过桥接系统,可以捕捉到log4net的输出(通过自定义附加器),并通过Common.Logging改道它,使第三部分类库的日志输出可以在您的应用程序的日志输出的背景下看待。

  1. A good logging abstraction should allow you to capture output from different logging frameworks in the same output file. Common.Logging calls this "bridging". Say that you have written an app using Common.Logging, backed by NLog. Now say that you are using a third party class library that is written using log4net directly. With a bridging system, you can capture the log4net output (via a custom appender) and reroute it through Common.Logging so that the third part class library's logging output can be viewed in the context of your app's logging output.

使用日志抽象还可以在开发过程中你试驾日志框架。你可能会开始时以为log4net的是路要走,但你要离开自己愿意尝试NLOG。使用日志抽象它是比较容易在两者之间切换。最终,你可以让这些日志框架的选择,但是,在此期间,你已经能够写出code山不依赖于一个特定的日志框架的任何方式。

Using a logging abstraction also allows you to "test drive" logging frameworks during development. You might start out thinking that log4net is that way to go, but you want to leave yourself open to trying NLog. Using a logging abstraction it is relatively easy to switch between the two. Ultimately, you can make the choice of which logging framework, but, in the meantime, you have been able to write mountains of code that is NOT dependent in any way on a specific logging framework.

这是你可以选择一个框架中对另一另一个原因是在你的工作环境。如果你已经在使用企业库的一部分,这可能足以把你推到使用企业库记录。

Another reason that you might choose one framework over another is the environment in which you work. If you are already using part of the Enterprise Library, that might be enough to push you into using Enterprise Library logging.

如果您正在开发在Silverlight?您可以选择使用类似木屐 - 钙的一部分。你也可以选择使用NLOG 2.0,这是Silverlight和WP7不兼容。

What if you are developing in Silverlight? You might choose to use something like Clog - part of Calcium. You might also choose to use NLog 2.0, which is Silverlight AND WP7 compatible.

System.Diagnostics程序插件(Ukadc.Diagnostics,Essential.Diagnostics)。这些都不是记录本身的框架。相反,它们重新有用的对象和扩展点,可以与现有的System.Diagnostics程序框架可以使用present集合。其中最好的东西,在我看来,那每个插件的添加是你的日志输出格式的功能,类似于如何使用log4net的和NLOG格式化。我没有用Essential.Diagnostics,但我已经尝试了Ukadc.Diagnostics,并认为这是真的很酷。它甚至很容易写自己的格式标记。

System.Diagnostics addons (Ukadc.Diagnostics, Essential.Diagnostics). These are not logging frameworks per se. Rather, they represent collections of useful objects and extension points that can be used with the existing System.Diagnostics framework. One of the best things, in my opinion, that each of these addons adds is the ability to format your logging output, similar to how you can format it with log4net and NLog. I have not used Essential.Diagnostics, but I have experimented with Ukadc.Diagnostics and think that it is really cool. It is even easy to write your own "formatting tokens".

我不知道这是否完全回答你的问题(这是pretty的广泛反正),但我认为有充足的食物在这里的想法。

I don't know if this completely answered your question (which is pretty broad anyway), but I think that there is plenty of food for thought here.

这篇关于什么时候应该使用跟踪VS Logger.NET,企业库,log4net的或Ukadc.Diagnostics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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