【问题标题】:Using DI to set a property in an NLog Target使用 DI 在 NLog 目标中设置属性
【发布时间】:2012-05-28 02:35:24
【问题描述】:
【问题讨论】:
标签:
dependency-injection
inversion-of-control
nlog
【解决方案1】:
重要的部分是设置这个自定义处理程序,这将为 nlog 使用的类型调用。
确保在完成此操作并注册依赖项后初始化 nlog
register your instances
.....
ConfigurationItemFactory.Default.CreateInstance = (Type type) =>
{
object instance;
if(unity/ninject/etc.TryResolve(type, out instance))
return instance;
else
return Activator.CreateInstance(type); //this is to support the other types that come with NLog
};
......
ConfigureNLog(...)