I had to do the same and this post was helpful.
The only downside to this is that you may end up logging too many exceptions. Since you say you are writing a class library, depending on the application that will use your library, you may not want to catch all the exceptions thrown by the application. To solve this issue, I recommend doing something like:
AppDomain.CurrentDomain.FirstChanceException += (sender, e) => {
if (e.Exception.TargetSite.DeclaringType.Assembly == Assembly.GetExecutingAssembly())
{
logger.ErrorFormat("Exception Thrown: {0}\n{1}", e.Exception.Message, e.Exception.StackTrace);
}
};
This way, you will only catch exceptions from your code. Hope this helps !