Unhandled Exceptions in C# Class Library for Logging Purposes Unhandled Exceptions in C# Class Library for Logging Purposes multithreading multithreading

Unhandled Exceptions in C# Class Library for Logging Purposes


If you have a limited set of entry points to the library, consider doing just what you suggest - use a .NET wrapper class or wrapper library to perform the actual interop and catch/log the exception in that wrapper class. Return an exception or error code that the calling VB6 library knows how to handle (whether that's rethrowing the exception or not depends on what the VB6 code can deal with).

CrazyDart suggests IOC, which is an interesting and valid alternative but also adds complexity and learning curve initially. Certainly have a look at IOC as well and concider it as a possibility.


You could use Castle Windsor and an interceptor for this. Its a good reason to use IOC on projects.

http://blog.andreloker.de/post/2009/02/20/Simple-AOP-integrating-interceptors-into-Windsor.aspx

I have used them for exception logging, just as you stated, and performance logging... among many other things you use interceptors for like transactions.


You could either look at using an AOP framework like Spring.NET or Unity, or alternatively look at a product such as PostSharp (though I have never personally tried PostSharp).