1

由于 https://robertmccarter.com/switching-to-nlog 和

log4net 与 Nlog

但是我认为   https://github.com/ServiceStack/ServiceStack 和 https://nuget.org/packages/ServiceStack.Logging.NLog保持通用接口和将来切换到其他提供商的能力。

有人知道使用 ServiceStack.Logging.NLog 而不是直接调用 NLog 的任何缺点/限制吗?

它会导致任何必要的性能下降吗?

是否有任何功能在直接调用 NLog 记录器时可用,但 ServiceStack 不支持?

4

2 回答 2

5

I've compared   ServiceStack ILog  , Common.Logging/ILog   and   NLog/Logger.cs and found that NLog has bigger number of overloads, that make it more type-safe. Also NLog has logic to  not process formatting if the logging for the particular record is disabled. 

Based on this I decided that using generic logging interface is YAGNI. If I would write library to be used in multiple applications with potentially different logging library used,  ServiceStack is a way to go.

However in application development with no immediate need to support more than one logging framework, it is more efficient to call Nlog directly. If in a future it would be decided to switch to other provider, global replace changes to call  ServiceStack or directly new provider should be relatively easy.

于 2013-07-20T22:07:36.940 回答
3

快速的答案是——你应该可以通过它们的通用日志接口使用 ServiceStack NLog 实现。看起来它会给你几乎所有你需要的东西。

您可以查看 ServiceStack NLog 实现代码@https ://github.com/ServiceStack/ServiceStack.Logging/tree/master/src/ServiceStack.Logging.NLog

我假设您仍然可以通过 NLog.config 文件配置 NLog,并且默认的 NLogFactory 会选择它 - 所以这仍然允许您执行特定于记录器的路由、多个目标等操作。

性能下降不会成为问题(除非您详细记录生产中的每件小事,但这取决于您,而不是框架)。

如果不详细介绍 NLog 实现,我不能说您将通过 ServiceStack NLog 获得所有功能 - 但就您需要记录代码而言,您会很高兴。

于 2013-07-18T13:35:12.200 回答