【发布时间】:2011-05-23 16:23:33
【问题描述】:
用导入的零件记录零件特定错误的首选方法是什么?例如。如果您有以下合同:
public interface IDoStuff
{
void DoYourStuff();
}
有多种实现方式:
[Export(typeof(IDoStuff))]
public class DoStuffCorrectly : IDoStuff
{
//implement void run
}
[Export(typeof(IDOstuff))]
public class DoStuffWithExceptions : IDoStuff
{
// implement void run and throws exception
}
并且你有一个使用 mef 组成部分的 Type。
public class DoStuffRunner
{
[ImportMany(typeof(IDoStuff))]
IEnumerable<IDoStuff> DoStuffPats {get;set;}
//some method that loops through the IEnumerable and calls run
public void Run()
{
foreach(IDostuff doit in DoStuffParts)
{
doit.Run();
}
}
}
在使用导入程序执行程序集时,我使用的是 entlib 异常处理和日志记录应用程序块。日志记录应用程序块被配置为向团队发送一般错误消息。我希望能够包含的一些信息是哪个部分失败了,以及可能哪个组收到了电子邮件。
这很简单,可以在应用程序配置中进行静态配置,但会导致添加的每个部分都是 1:1 的配置,并且会破坏将 dll 放入 bin 的目的。如果您可以控制零件装配中的配置,那就太好了。
那么,有哪些可能的方法可以让部件公开信息,从而允许导入的部件提供与 MEF 意识形态相冲突的日志记录配置信息?
【问题讨论】:
标签: c# .net logging enterprise-library mef