记录 mef 部件的部件特定错误消息
记录导入零件的零件特定错误的首选方法是什么? EG 如果您有以下合同:
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 来组成各个部分的类型。
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 意识形态的日志记录配置信息?
What is a preferred approach for logging part specific errors with imported parts? E.G. if you have the following contract:
public interface IDoStuff
{
void DoYourStuff();
}
with multiple implementations:
[Export(typeof(IDoStuff))]
public class DoStuffCorrectly : IDoStuff
{
//implement void run
}
[Export(typeof(IDOstuff))]
public class DoStuffWithExceptions : IDoStuff
{
// implement void run and throws exception
}
and you have a Type that uses mef to compose the parts.
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();
}
}
}
In the executing assembly with the importer I am using entlib Exception Handling and Logging Application blocks. The logging application block is configured to send general error messages to the team. Some of the information that I would like to be able to include is which part failed, and possibly which group gets the email.
This is simple enough to configure statically in the app config, but would lead to a 1:1 configuration for each part that is added and kind defeats the purpose of dropping the dll in the bin. It would be neat if you could control the configuration in the part's assembly.
So, what are some possible approaches that would allow a part to expose information that could allow an imported part to provide logging configuration information that would jive with the MEF ideology?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MEF 方法是将日志记录接口导入到您的插件中和/或通过使用导出类上的自定义属性导出配置记录器所需的任何元数据。
我对该日志库(我们使用 log4net)不太熟悉,不知道您需要哪些元数据,或者如果您没有导入日志记录接口,如何以统一的方式启动日志记录。
The MEF way is to import a logging interface into your plugins and/or export whatever metadata you need to configure your logger by using custom attributes on your exported class.
I'm not really familiar enough with that logging library (we use log4net) to know what metadata you need or how logging would be actuated in a unified manner if you didn't import a logging interface interface.