ILogger无需配置?

时间:2013-09-16 16:20:33

标签: c# ninject nlog ninject-logging

我正在使用NLog(v2.0)尝试Ninject的Logging扩展(v3.0),从我读过的内容来看,我不应该配置任何东西,就像 auto-魔法我需要做的只是在需要的地方声明ILogger依赖。

我保留了我已经拥有的nlog.config文件,并删除了创建记录器的所有代码,而是将ILogger放入我的类的构造函数中。

我在作文根处获得ActivationException,... Ninject无法解析ILogger

我错过了什么?

我基本上归结为:

public static void Main(string[] args)
{
    // nothing special here, binds IMyApp to MyApp.
    using (var kernel = new StandardKernel(new NinjectConfig()))
    {
        var app = kernel.Get<IMyApp>(); // MyApp has a ILogger dependency **blows up here**
        app.Run(args);
    }
}

这是一个控制台应用程序,它的价值是什么......日志记录扩展应该像这样工作吗?


文档说:

  

确保在请求类型实例之前让内核加载新的Log4NetModule或NLogModule

但如果我这样做:

    using (var kernel = new StandardKernel(new NLogModule(), new NinjectConfig()))
    {
        ...

...... ReSharper不知道NLogModule是什么。

1 个答案:

答案 0 :(得分:0)

下载Ninject.Extensions.Logging的nuget包是不够的。

您还需要下载Ninject.Extensions.Logging.nlog2的nuget包,其中包含绑定NLogModule界面所需的ILogger类。

还有一个可用于log4net日志记录的nuget包。

此:

var kernel = new StandardKernel(new NinjectConfig())

是否需要使一切正常运行 - 无需明确加载new NLogModule()