Many logging frameworks provide class-specific loggers:
NLog: Logger.GetLogger(typeof(MyClass).Name)
Serilog: Log.Logger.ForContext<MyClass>()
To be able to inject these class specific loggers, one would do something like this in Ninject:
Bind<ILog>().ToMethod(context =>
{
var typeForLogger = context.Request.Target != null ? context.Request.Target.Member.DeclaringType : context.Request.Service;
return context.Kernel.Get<ILoggerFactory>().GetLogger(typeForLogger);
});
where context.Request.Target
provides the type that will receive the injection.
I can't find any way to do the same using LightInject; is this feature not supported (yet)?