Ninject 2、日志记录和 WebForms
正式发布的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然 Ninject.Web 具有 ILogger 属性,但它不记录任何内容。
如果要完全禁用 Ninject.Extensions.Logging,请创建并绑定 ILoggerFactory 的实现,该实现从所有方法返回 null。
或者,如果您想使用 log4net 启用它,请从 ninject.org 获取 Ninject.Extensions.Logging 并引用 Ninject.Extensions。来自您的项目的 Logging.Log4net。它将被 Ninject 2.0 自动加载。
如果您从源代码构建 Ninject.Web,则可以通过以下方式删除日志记录扩展:
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: