将 Common.Logging 与 Asp.net MVC 和温莎城堡结合使用

发布于 2024-10-04 19:55:27 字数 100 浏览 1 评论 0 原文

我想使用 Common.Logging 来删除对特定日志记录框架的依赖关系,但我不确定如何使用 Castle Windsor IoC 容器连接 ILog 接口。有办法做到这一点吗?谢谢!

I would like to use Common.Logging to remove dependencies on a specific logging framework, but I'm not sure how to wire up the ILog interface using the Castle Windsor IoC container. Is there a way to do this? Thanks!

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

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

发布评论

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

评论(2

情域 2024-10-11 19:55:27

你真的想两者都做吗? (使用 Common.Logging 并通过 Castle Windsor IoC 注入它?)使用 Common.Logging 允许您的应用程序不硬​​依赖于特定的日志框架(例如 log4net、NLog、Enterprise Logging)。我不使用 Castle,但我的理解是它的日志记录工具也有类似的目标。您可以将 Castle Windsor 配置为使用特定的日志记录框架(例如 log4net 或 NLog),但您的应用程序不需要知道最终使用的是哪个日志记录框架。

通过温莎城堡注入 Common.Logging 看起来就像穿着腰带和吊带来撑起你的裤子!您将通过温莎城堡自己的日志记录抽象设施注入日志记录抽象!

我的猜测是,您确实想使用一种技术或另一种技术(Common.Logging 或 Castle Windsor 的日志记录工具)。

如果您确实想通过 Castle Windsor 注入 Common.Logging,您可能会发现此链接很有用:

使用 Castle.Facilities.Logging 和 log4net 进行日志记录

除此之外,它还描述了如何编写您自己的自定义 Castle Windsor 日志记录工具以由 Castle Windsor 注入。

Do you really want to do both? (Use Common.Logging AND inject it via Castle Windsor IoC?) Using Common.Logging allows your app to NOT have a hard dependency on a specific logging framework (e.g. log4net, NLog, Enterprise Logging). I don't use Castle, but my understanding is that its logging facility has a similar goal. You can configure Castle Windsor to use a specific logging framework (such as log4net or NLog), but your application does not need to be aware of which logging framework is ultimately being used.

Injecting Common.Logging via Castle Windsor seems like wearing a belt AND suspenders to hold your pants up! You would be injecting a logging abstraction via Castle Windsor's own logging abstraction factility!

My guess is that you really want to use one technology or the other (Common.Logging or Castle Windsor's logging facility).

If you really do want to inject Common.Logging via Castle Windsor, you might find this link useful:

Logging with Castle.Facilities.Logging and log4net

Among other things, it describes how to write your own custom Castle Windsor logging facility to be injected by Castle Windsor.

美胚控场 2024-10-11 19:55:27

为 Common.Logging 创建您自己的设施,查看它如何为现有的 温莎的记录设施。 Common.Logging 可能有一个记录器工厂,您可以在该设施中使用它来创建记录器。

或者您可以节省自己的工作,只需使用 Castle 的 ILogger 以及日志记录功能:Windsor 将为您在您的类中注入 ILogger 实例。适用于 log4net 和 NLog v2。

Create your own facility for Common.Logging, checkout how it's done for the existing Logging Facility in Windsor. Common.Logging probably has a logger factory you would utilize in the facility to create a logger.

Or you could save yourself the work and just use Castle's ILogger with the Logging facility: Windsor will inject ILogger instances in your classes for you. Works with log4net and NLog v2.

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