【问题标题】:There's a way to log "Swallowed Exceptions" via Postsharp?有一种方法可以通过 Postsharp 记录“吞下的异常”吗?
【发布时间】:2014-06-05 00:48:54
【问题描述】:

我对 postsharp 比较陌生,但我确实在 postsharp 的帮助下使用 entlib、log4net、异常日志记录和异常屏蔽为异常日志记录编写了一些不错的方面。这对我目前使用的所有东西来说都是非常简单和有用的东西。

但是当我尝试注入一个方面以在 catch{} 之后立即记录异常时,即使异常被吞下,我也找不到方法。

说我不能更改目标代码也许很有用。一切都必须在方面做。我确实使用派生的 OnExceptionAspect 成功记录了未被吞咽的异常。

我曾想过用 postsharp sdk 注入 MSIL,但不喜欢这条路。

例如

public IList<DatabaseTable> GetDataTables()
    {
        try
        {
           if (this._databaseTables == null)
               this._databaseTables = this.LoadTablesFromDatabase();

           return _databaseTables;
        }
        catch // swallowed exception
        {
           // I want to log here!
           // other conpensation stuffs....
        }
    }

有什么想法吗?

谢谢

【问题讨论】:

    标签: postsharp


    【解决方案1】:

    这对于当前的任何现成方面都是不可能的,因为它需要重写方法的 catch 块。使用 SDK 似乎是唯一可用的选项。

    【讨论】:

    • 是否有任何示例、文档或教程可供我深入了解,让我在这方面占得先机?
    猜你喜欢
    • 1970-01-01
    • 2018-07-16
    • 2014-02-24
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多