如何在我的MVC3项目正确配置Ninject.Extensions.Logging.Log4Net [英] How To Properly Configure Ninject.Extensions.Logging.Log4Net in my MVC3 project

查看:290
本文介绍了如何在我的MVC3项目正确配置Ninject.Extensions.Logging.Log4Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想正确使用Ninject注入log4net的日志记录到我MVC3应用程序。我使用的 Ninject.MVC3 包,让我有一个自动扩展App_Start方法,并包含结合所有依赖性的RegisterServices方法NinjectMVC3类。我也有在 Ninject.Extensions.Logging.Log4Net 包,但我不知道如何使用它。我已经知道如何在我的web.config配置log4net的,但不知道如何使用这个扩展DI

I am trying to properly use Ninject to inject log4net logging into my MVC3 application. I am using the Ninject.MVC3 package, so I have the NinjectMVC3 class that automatically extends the App_Start method and contains the RegisterServices method that binds all dependencies. I also have the Ninject.Extensions.Logging.Log4Net package, but I don't know how to use it. I already know how to configure log4net in my web.config, but don't know how to use this extension for DI.

我看了所有的以下文章/职位,但他们都不来定义如何正确设置为DI记录的项目。

I have read all the following articles/posts, but none of them seem to define how to properly setup a project for DI logging.

在<一个href=\"http://dotnetdarren.word$p$pss.com/2010/07/29/logging-in-mvc-part-4-log4net/\">http://dotnetdarren.word$p$pss.com/2010/07/29/logging-in-mvc-part-4-log4net/,达伦
提供了一个伟大的文章,但似乎并没有处理DI(至少我没有看到它)。

At http://dotnetdarren.wordpress.com/2010/07/29/logging-in-mvc-part-4-log4net/, Darren provides a great article, but doesn't seem to deal with DI (at least I don't see it).

使用Ninject填补log4net的依赖
雷莫Gloor这里指出的扩展应该提供所有需要执行,但它并没有显示如何初始化它code。

At Using Ninject to fill Log4Net Dependency, Remo Gloor states here that the extensions should provide all that's needed for implementation, but it doesn't show the code of how to instantiate it.

在<一ninject.extensions.logging文档href=\"https://github.com/ninject/ninject.extensions.logging/wiki/Using\">https://github.com/ninject/ninject.extensions.logging/wiki/Using是非常有限的最好的。我已经重新阅读了很多次,仍然没有看到如何使用绑定在NinjectMVC3类注射,或如何从我的例如控制器类调用记录器的具体例子。

The documentation for ninject.extensions.logging at https://github.com/ninject/ninject.extensions.logging/wiki/Using is very limited at best. I have re-read it many times, and still don't see how to use bind the injection in the NinjectMVC3 class, or concrete examples of how to call the logger from my controller class for example.

目前最有前途的文章,Moosaka提供在<一一些伟大的code href=\"http://stackoverflow.com/questions/7227628/ninject-extensions-logging-log4net-unexpected-behavior\">Ninject.Extensions.Logging.Log4net意外的行为,但是当我尝试它,我在 ILogger记录器=新的记录器(类型)获得的的LoggerFactory编译错误; 指出无法访问受保护的构造记录仪在这里。此外,他国塔克这整个烂摊子掳到一个单独的类库。这是否意味着作为一个整体单独的项目?

At the most promising article, Moosaka provides some great code at Ninject.Extensions.Logging.Log4net unexpected behavior, but when I try it, I get a compile error in the LoggerFactory at ILogger logger = new Logger(type); stating "Cannot access protected constructor 'Logger' here". Also, he states to "Tuck this whole mess away into a separate class library". Does that mean as a whole separate project?

我只是迷路在所有的不同选项和注明日期的帖子,并希望有关如何使用依赖关系注入与Ninject和log4net的在我的MVC3项目中的任何输入。另外,如果它很重要,我所有的Ninject code是在我的领域的项目,但无论从域名和Web项目所做的记录需求(在我的单元测试嘲笑)。任何帮助是AP preciated。

I'm just getting lost in all the differing options and dated posts and would like any input on how to use Dependancy Injection with Ninject and Log4Net in my MVC3 project. Also, if it matters, all of my Ninject code is in my domain project, but the logging needs done from both the domain and web project (and mocked in my unit tests). Any help is appreciated.

推荐答案

您应该不必配置除正常的log4net配置任何东西。

You shouldn't have to configure anything except the normal log4net config.

所有你需要做的就是,无论你想记录到注入ILogger。
<一href=\"https://github.com/ninject/ninject.extensions.logging/wiki/Using\">https://github.com/ninject/ninject.extensions.logging/wiki/Using

All you have to do is to inject a ILogger wherever you want to log. https://github.com/ninject/ninject.extensions.logging/wiki/Using

这篇关于如何在我的MVC3项目正确配置Ninject.Extensions.Logging.Log4Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆