poolfoot
poolfoot

Reputation: 53

There's a way to log "Swallowed Exceptions" via Postsharp?

I'm relatively new to postsharp but I did code some nice aspects for Exception logging with entlib, log4net, exception logging and exception shielding with the help of postsharp. That was all surprinsingly simple and useful stuff for me that I use currently.

But when I tried to inject an aspect to log an exception immediatetly after a catch{} even if an exception is swallowed, I cant find a way.

Maybe its useful to say that I can't change the target code. Everything must be done in the aspect. I did successfully log unswallowed exceptions with a derived OnExceptionAspect.

I flirted with the idea to inject MSIL with the postsharp sdk, but dont like this path.

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

Any ideas?

Thanks

Upvotes: 1

Views: 94

Answers (1)

Daniel Balas
Daniel Balas

Reputation: 1850

This is not possible with any of current ready-made aspects as it would require to rewrite the method's catch blocks. Using SDK seems like the only option available.

Upvotes: 1

Related Questions