Question

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?

Was it helpful?

Solution

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

new StandardKernel().Get<ILoggerFactory>().GetCurrentClassLogger();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top