I'm using Ninject for my DI and Ninject.Extensions.Logging (with NLog) for Logger injection. I want to get an instance of Logger in my Main void at the start of the program.

I tried this code:

private static void Main()
{
    var logger = new StandardKernel(new NLogModule()).Get<ILogger>();
}

But I get an error Error loading module 'Ninject.Extensions.Logging.NLog2.NLogModule' of type NLogModule.

How can I get a Logger instance in this method?

有帮助吗?

解决方案

Extensions are loaded automatically. You cant load it again manually. Just use

new StandardKernel().Get<ILoggerFactory>().GetCurrentClassLogger();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top