PostSharp - 我做错了什么?
我有一个 Company.Business 项目,我试图用 PostSharp 来包装我的业务层。在 Company.AOP 项目中,我有一个方法边界方面来使用 EL 日志记录应用程序块,如下所示:
[Serializable]
public class MethodExcecutionAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
base.OnEntry(eventArgs);
//Log message
}
public override void OnException(MethodExecutionEventArgs eventArgs)
{
base.OnException(eventArgs);
//Log message
}
public override void OnExit(MethodExecutionEventArgs eventArgs)
{
base.OnExit(eventArgs);
//Log message
}
}
足够简单;它只是记录时间点。我尝试通过以下方式定位整个业务层:
[assembly: MethodExcecution(AttributeTargetTypes = "*",
AttributeTargetAssemblies = "Company.Business",
AttributeTargetTypeAttributes = MulticastAttributes.Public,
AttributeTargetMemberAttributes = MulticastAttributes.Public)]
但编译后,我检查 DLL,它没有像网站上的示例那样包装代码。这种方法有什么问题吗?
我确实安装了它,并且验证了它正在运行;它在编译时生成输出,且错误为零。
谢谢。
I have a project Company.Business that I'm trying to target with PostSharp to wrap my business layer. In the project Company.AOP, I have a method boundary aspect to use EL logging application block as such:
[Serializable]
public class MethodExcecutionAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
base.OnEntry(eventArgs);
//Log message
}
public override void OnException(MethodExecutionEventArgs eventArgs)
{
base.OnException(eventArgs);
//Log message
}
public override void OnExit(MethodExecutionEventArgs eventArgs)
{
base.OnExit(eventArgs);
//Log message
}
}
Simple enough; it simply logs the point in time. I try to target my entire business layer via:
[assembly: MethodExcecution(AttributeTargetTypes = "*",
AttributeTargetAssemblies = "Company.Business",
AttributeTargetTypeAttributes = MulticastAttributes.Public,
AttributeTargetMemberAttributes = MulticastAttributes.Public)]
But after compile, I inspect the DLL and it does not wrap the code as in the examples on the web site. What is wrong with this approach?
I do have it installed, and I verified it is running; it is generating output during compile time, with zero errors.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当前版本中存在一个错误:如果您指定 AttributeTargetAssemblies,它将仅查看程序集引用,而不是当前项目。
因此,如果您想向当前项目添加方面,请删除 AttributeTargetAssemblies。
There's a bug in the current release: if you specify AttributeTargetAssemblies, it will look only at assembly references, not the current project.
So if you want to add aspects to the current project, remove AttributeTargetAssemblies.