I have a class whose constructor looks like
public class Foo(NLog.Logger logger)
I am using StructureMap 2.6.4.1 to do dependency injection (via constructor injection entirely, no property injection). I am using NLog for my logging. One of the nice features of NLog is that one can route log events to different targets via the loggers having names. It's very flexible, therefore, to name the loggers after the owning type's fully qualified name (In the example above, it would be <namespace>.Foo
)
Castle Windsor's logging facility will supply a logger to the instances that require them, named for the class of the owning instance.
However, I haven't been able to get StructureMap to do this.
I've tried the EnrichWith((context, type) => {})
method, but context.ParentType
is always null. Here's an example of my registry:
public class InfrastructureRegistry : Registry
{
public InfrastructureRegistry()
{
For<NLog.Logger>().Use<NLog.Logger>()
.EnrichWith((context, pluginType) =>
NLog.LogManager.GetLogger(context.ParentType.FullName)
);
}
}
I'm perplexed. How do I do what I want?