【问题标题】:Is the approach for ExceptionHandling changed in PostSharp 5.x?PostSharp 5.x 中的 ExceptionHandling 方法是否发生了变化?
【发布时间】:2017-08-17 13:34:46
【问题描述】:

在 PostSharp 5.x 之前,异常处理是通过继承 OnExceptionAspect() 来完成的。 5.x 中是否有类似于使用 AuditServices.RecordPublished 事件处理程序完成的审核日志的新方法?

【问题讨论】:

    标签: postsharp


    【解决方案1】:

    要记录方法引发的异常,您可以使用 PostSharp 诊断库 - 请参阅 http://doc.postsharp.net/add-logging

    要仅记录异常(不是每个方法进入和退出),请使用LogExceptionsAttribute 自定义属性而不是LogAttribute 自定义属性。见http://doc.postsharp.net/t_postsharp_patterns_diagnostics_logexceptionattribute

    要在方法引发异常时执行其他操作,仍然存在OnExceptionAspect 方面。见http://doc.postsharp.net/exception-handling

    【讨论】:

    • 当使用 OnExceptionAspect 拦截异常时,我可以在类级别或方法级别应用该属性。如何在装配级别或解决方案级别应用它?
    • 应用方面记录在doc.postsharp.net/applying-aspects。在doc.postsharp.net/attribute-multicasting 中描述了应用于整个程序集。通过在 .sln 文件所在的文件夹中创建一个名为 .pssln 的文件并按照doc.postsharp.net/xml-multicasting 中的描述进行设置,可以将各个方面应用于整个解决方案。 PostSharp 配置在doc.postsharp.net/configuration-system 进行了描述。
    • doc.postsharp.net/xml-multicasting 处理 psproj。 samples.postsharp.net 中的示例没有 pssln 文件。您能给我提供任何带有 OnExceptionAspect 和 pssln 的示例吗?
    • 配置文件内容相同。不同之处在于 PostSharp 在哪里寻找它们。 (如doc.postsharp.net/configuration-system-“众所周知的配置文件”中所述。)
    • 我有 ExceptionSwallow.dll,其中有以下代码 namespace ExceptionSwallow { [PSerializable] public sealed class SwallowException : OnExceptionAspect { } } 我在 PSSLN 中有以下内容 ` ' 我收到错误“错误 PS0201:找不到类型 'ExceptionSwallow.SwallowException, ExceptionSwallow'。
    猜你喜欢
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多