I want to be able to log first chance exceptions in an ASP.NET app, and the way you do this is by handling AppDomain.CurrentDomain.FirstChanceException:
AppDomain.CurrentDomain.FirstChanceException +=
(object source, FirstChanceExceptionEventArgs e) =>
{
Console.WriteLine("FirstChanceException event raised in {0}: {1}",
AppDomain.CurrentDomain.FriendlyName, e.Exception.Message);
};
But the thing I'm not sure about is when you should call this in an ASP.NET app. Is there one AppDomain per Application, and so this could go in the Application_Start
event? Or could there be multiple AppDomains and this would miss some of them? Or could this somehow add the handler twice?
In other words, where should this event handler creation code go?