문제

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