PostSharp - 我做错了什么?

发布于 2024-09-24 06:03:12 字数 1045 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久隐师 2024-10-01 06:03:12

当前版本中存在一个错误:如果您指定 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文