You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the NLog and NLog2 ones are likely to do the same AFAICT
in Main, put these 2 lines and run:
IKernel standardKernel = new StandardKernel();
var logger = standardKernel.Get<ILogger>();
throws a null ref due to Target being null (since we're asking for the instance directly, instead of having it injected into a class) in LoggerFactoryBase.GetLogger
public ILogger GetLogger(IContext context)
{
return this.GetLogger(context.Request.Target.Member.DeclaringType);
}
I'm getting a "TypeLoadException: Inheritance security rules violated by type 'Ninject.Extensions.Logging.LoggerModuleBase'" locally (unrelated to this issue AFAICT), so I haven't been able to confirm this, but a failing test for this behavior should be:
[Fact]
public void CanManuallyGetILoggerInstance()
{
using (var kernel = this.CreateKernel())
{
var loggerClass = kernel.Get<ILogger>();
loggerClass.Should().NotBeNull();
loggerClass.Type.Should().Be(typeof(ILogger));
}
}
Certainly a user of ninject should have ILogger injected and never need to fetch ILogger directly (service locator anti-pattern), but in trying to use the ninject logging extension with a codebase that (unfortunately) has some places fetching instances manually, this null ref keeps it from being usable.
The least-code workaround AFAICT is rebinding ILogger (currently bound in LoggerModuleBase.Load) - here's what a modified LoggerModuleBase might look like (not sure if using the service type as a fallback is really desirable or not)
This might be "by design", but off-hand it seemed a little harsh as an end-user experience.
steps:
create new console app (happens to be .NET 4.5, but that's not likely important)
Install-Package Ninject.Extensions.Logging.Log4net
in Main, put these 2 lines and run:
throws a null ref due to Target being null (since we're asking for the instance directly, instead of having it injected into a class) in LoggerFactoryBase.GetLogger
I'm getting a "TypeLoadException: Inheritance security rules violated by type 'Ninject.Extensions.Logging.LoggerModuleBase'" locally (unrelated to this issue AFAICT), so I haven't been able to confirm this, but a failing test for this behavior should be:
Certainly a user of ninject should have ILogger injected and never need to fetch ILogger directly (service locator anti-pattern), but in trying to use the ninject logging extension with a codebase that (unfortunately) has some places fetching instances manually, this null ref keeps it from being usable.
The least-code workaround AFAICT is rebinding ILogger (currently bound in LoggerModuleBase.Load) - here's what a modified LoggerModuleBase might look like (not sure if using the service type as a fallback is really desirable or not)
The text was updated successfully, but these errors were encountered: