Ninject 2、日志记录和 WebForms

发布于 2024-08-22 18:31:00 字数 1191 浏览 5 评论 0原文

正式发布的 Ninject 2 不再包含对 WebForms、MasterPages 等 IoC 的 WebForms 特定功能的引用。它现在被分成插件/扩展;在本例中是 http://github.com/idavis/ninject.web 扩展。然而,我的问题是,存在对 log4net (或 NLog)的依赖,并且我找不到任何有关如何将其配置为与我当前的 log4net 配置集成或完全删除它的文档(即将日志记录设置为 null,所以我不不可能有两个 log4net 配置正在运行)。

http: //markmail.org/message/7iv7nltanz6ve4ga#query:Error%20activating%20ILoggerFactory%20ninject.web+page:1+mid:6o4q6ee2js2k4gfp+state:results 引用了具有相同问题的其他人,但同样,没有真正的文档关于如何处理它。我已经浏览了所有内容的来源,并且一定遗漏了一些明显的东西。

任何人都可以为我指明处理此问题的最佳方法的正确方向,以便我仍然可以轻松地将 Ninject 与 WebForms 集成,但不会运行无关的日志记录服务吗?或者不用担心 Global.asax 上的以下内容:

    protected override IKernel CreateKernel()
    {
        IKernel kernel =
        new StandardKernel(new SomeMyModule(), new Log4netModule());
        return kernel;
    }

我目前正在 global.asax 中通过以下方式启动我的 log4net 配置

 private readonly static ILog Log = LogManager.GetLogger(typeof(Global));:

The officially released Ninject 2 no longer includes reference to the WebForms-specific functionality for IoC for WebForms, MasterPages, etc. It's now separated out into plugins/extensions; which in this case is the http://github.com/idavis/ninject.web extension. My problem however is that there's a dependency on log4net (or NLog) and I can't find any documentation on how to configure it to either integrate with my current log4net configuration, or remove it altogether (i.e. set the logging to null so I don't conceivably have two log4net configurations running).

http://markmail.org/message/7iv7nltanz6ve4ga#query:Error%20activating%20ILoggerFactory%20ninject.web+page:1+mid:6o4q6ee2js2k4gfp+state:results references others with the same issue, but again, no real documentation on what to do with it. I've looked through the source for all of it, and must be missing something obvious.

Can anyone point me in the right direction for the best way of dealing with this so I can still easily integrate Ninject with WebForms, but not have extraneous logging services running? Or not worry about something like the following on the Global.asax:

    protected override IKernel CreateKernel()
    {
        IKernel kernel =
        new StandardKernel(new SomeMyModule(), new Log4netModule());
        return kernel;
    }

I'm currently kickstarting my log4net configuration in global.asax via

 private readonly static ILog Log = LogManager.GetLogger(typeof(Global));:

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

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

发布评论

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

评论(1

请远离我 2024-08-29 18:31:00

虽然 Ninject.Web 具有 ILogger 属性,但它不记录任何内容。

如果要完全禁用 Ninject.Extensions.Logging,请创建并绑定 ILoggerFactory 的实现,该实现从所有方法返回 null。

或者,如果您想使用 log4net 启用它,请从 ninject.org 获取 Ninject.Extensions.Logging 并引用 Ninject.Extensions。来自您的项目的 Logging.Log4net。它将被 Ninject 2.0 自动加载。

如果您从源代码构建 Ninject.Web,则可以通过以下方式删除日志记录扩展:

  • 删除对该程序集的引用
  • 从拥有它的 5 个类中删除 ILogger 成员

While Ninject.Web has ILogger properties, it does not log anything.

If you want to disable Ninject.Extensions.Logging entirely, create and bind an implementation of ILoggerFactory that returns null from all methods.

Or if you want to enable it with log4net, fetch Ninject.Extensions.Logging from ninject.org and reference Ninject.Extensions.Logging.Log4net from your project. It will be automatically loaded by Ninject 2.0.

If you are building Ninject.Web from source, you could remove the logging extension by:

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