有一种方法可以记录" Swallowed Exceptions"通过Postsharp?

时间:2014-06-04 00:03:59

标签: postsharp

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

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

也许说我无法更改目标代码很有用。一切都必须在方面完成。我使用派生的OnExceptionAspect成功地记录了未流动的异常。

我想到用postharp sdk注入MSIL,但不喜欢这条路。

E.G。

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....
        }
    }

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:1)

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