.NET 世界有日志记录外观吗?

发布于 2024-08-30 07:12:47 字数 368 浏览 2 评论 0原文

我对 .NET 堆栈有点陌生,我想知道 .NET 堆栈是否有相当于 slf4j 的东西。 NET平台。对我来说,登录到 Facade 并能够根据需要更换日志记录实现是有意义的。此外,当我需要使用针对我没有使用的单个日志框架进行编码的第三方库时,slf4j 中提供的包装器 API 多次帮助我。

是否有一个项目可以充当 log4net、nLog 和 Enterprise Library 等记录器之间的外观?是否有包装器允许我快捷地调用这些库并将它们定向到另一个库?我应该自己启动一个开源项目来做这件事吗?这个问题是否重复,因为我不知道正确的提问方式?相反,是使用面向方面编程来实现此目的的常见方法吗?

I'm somewhat new to the .NET stack and I was wondering if there is an equivalent to slf4j for the .NET platform. For me, logging to a Facade and being able to swap out logging implementations as needed just makes sense. Furthermore, the wrapper APIs available in slf4j have saved me many times when I needed to use a third-party library that was coded against a single logging framework that I wasn't using.

Is there a project out there that acts as a facade between loggers like log4net, nLog and Enterprise Library? Are there wrappers that allow me to shortcut calls to those libraries and direct them to another library? Should I start out an open source project to do this myself? Is this question a duplicate because I don't know the right way to ask? Conversely, is the common way to do this using aspect orient programming?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

自我难过 2024-09-06 07:12:47

抱歉,我用过这个东西,我忘了它不是 Apache 版本。它实际上是开源的,并且是称为通用基础设施的项目的一部分。它也称为通用日志记录。它适用于 MS Enterprise、log4net 等。效果很好。

Excuse I used this thing and I forgot it wasn't the Apache version. It's actually open-source and part of a project called common infrastructure. It is also called common logging. It works with MS Enterprise, log4net and others. It works well.

攀登最高峰 2024-09-06 07:12:47

查看温莎城堡日志工具

基本代码位于此处。 Log4net 适配器此处。 NLog 适配器此处

添加了 Serilog 适配器。

如果没有适配器,则支持 ConsoleLogger、DiagnosticsLogger、StreamLogger 和 NullLogger。

为任何其他日志框架编写适配器都非常容易。

Take a look at Castle Windsor Logging Facility.

Base code is here. Log4net adapter here. NLog adapter here.

Added adapter for Serilog.

Without the adapters there is suppor for ConsoleLogger, DiagnosticsLogger, StreamLogger and NullLogger.

It's pretty easy to write adapters to any other logging framework.

被你宠の有点坏 2024-09-06 07:12:47

.NET Core 更新:

Update for .NET Core:

情绪少女 2024-09-06 07:12:47

我有同样的问题。经过上面推荐的内容后,我发现了 Ninject.Extensions.Logging

很棒,因为无论如何,外观与 DI 结合起来最有意义

它附带了 NLog、NLog2 和 NLog 的代理。 log4net。

这是一个关于如何将其与 NLog 结合使用的很好的示例:
http://blog.tonysneed.com/2011/ 10/09/using-nlog-with-dependency-injection/

我明白,这个问题已经有几年了,但由于其他用户的完整性,我仍然选择发布这个'解决方案'

I had the same Problem. After going through those recommended above, I discovered Ninject.Extensions.Logging

Which is great since a facade makes best sense in combination with DI anyway

It comes with proxies for NLog, NLog2 & log4net.

Here is a nice example on how to use it in combination with NLog:
http://blog.tonysneed.com/2011/10/09/using-nlog-with-dependency-injection/

I understand, that this question is already a couple of years old, but due to completeness for other users, I still chose to post this 'Solution'

尹雨沫 2024-09-06 07:12:47

由于这是编写的,另一个有趣的日志包装器称为 Fody.Anotar 出现了。截至今天,它可能是其中最完整的。除伐木设施外,其他大部分都相当过时,仅支持最古老的伐木工。

它具有适用于 NLog、Log4Net、Serilog、CommongLogging、Catel、LibLog、MetroLog、NServiceBus 和 Splat 的适配器,并允许您为自己的库创建适配器。

您可以使用 Nuget 来安装它。查找 Anotar.*.Fody 包,例如 Anotar.NLog.Fody。

Since this was written another interesting logging wrapper called Fody.Anotar has appeared. As of today, it's probably the most complete of all of them. Most of the other, but Logging Faciliy, are quite outdated, supporting only the oldest loggers.

It has adapters for NLog, Log4Net, Serilog, CommongLogging, Catel, LibLog, MetroLog, NServiceBus and Splat, and allows you to create an adapter for your own library.

You can use Nuget to install it. Look for Anotar.*.Fody packages, for example Anotar.NLog.Fody.

萌︼了一个春 2024-09-06 07:12:47

不知何故,我发现这里的所有解决方案都不令人满意,特别是对于库/API。尽管我从未想过我会这样做,但我实际上编写了一个开源“记录器”,它应该可以处理大多数问题。

也许你可以看看 Dapplo.Log,你可以从 NuGet 获取它。

这个想法是在您的库中使用 Dapplo.Log,并且使用它的项目可以将(在需要时)任何日志输出定向到他们选择的记录器。引导输出的示例可以在测试中找到,其中包含一些主要框架的实现 这里

它可能还不完美,我欢迎拉请求或票证。

I somehow found all solutions in here unsatisfying, especially for libraries/APIs. Although I never thought I would, I actually wrote an Open Source "logger" which should handle most concerns.

Maybe you can have a look at Dapplo.Log, you can get it from NuGet.

The idea is to use Dapplo.Log in your library, and the project which uses this can than direct (when needed) any log output to their logger of choice. Examples for directing the output can be found in the tests, with implementations of some major frameworks here.

It's probably not perfect (yet), and I welcome pull-requests or tickets.

jJeQQOZ5 2024-09-06 07:12:47

发现自己处于这种情况,我花了一些时间阅读所有答案并研究一个好的解决方案。大多数提议的堆栈/框架/抽象现在都已过时,要么当前未维护,要么不再流行。

然后我遇到了 LibLog,它现已被弃用,并且其自述文件明确推荐 Microsoft.Extensions.Logging.Abstractions因为它现在是 .NET 生态系统中事实上的标准日志记录接口”。

(郑重声明,Microsoft.Extensions.Logging.Abstractions 现已包含在 .NET 运行时 从 ASP .NET 日志记录移至那里之后)

Finding myself in this situation, I spent some time reading all answers and researching for a good solution. Most of the proposed stacks/frameworks/abstractions are now old and either not currently maintained or not popular anymore.

I then encountered LibLog, which is now deprecated, and whose ReadMe explicitly recommends Microsoft.Extensions.Logging.Abstractions "as it is now the defacto standard logging interface in the .NET ecosystem".

(For the record, Microsoft.Extensions.Logging.Abstractions is now included in .NET Runtime after it was moved there from ASP .NET Logging)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文