I'm using Ninject for DI in my asp.net application, so my Global class inherits from NinjectHttpApplication.
In my CreateKernel(), I'm creating my custom modules and DI is working fine for me.
However, I notice that there is a Logger property in the NinjectHttpApplication class, so I'm trying to use this in Application_Error whenever an exception is not caught.
I think I'm creating the nlog module correctly for Ninject, but my logger is always null. Here's my CreateKernel:
protected override Ninject.Core.IKernel CreateKernel()
{
IKernel kernel = new StandardKernel(new NLogModule(), new NinjectRepositoryModule());
return kernel;
}
But in the following method, Logger is always null.
protected void Application_Error(object sender, EventArgs e)
{
Exception lastException = Server.GetLastError().GetBaseException();
Logger.Error(lastException, "An exception was caught in Global.asax");
}
To clarify, Logger is a property on NinjectHttpApplication of type ILogger and has the [Inject] attribute
Any idea how to inject correctly into Logger?