Selon le type d'application (ASP.NET/Console, etc.), il existe différentes approches à adopter.
Pour les applications Windows Forms c'est la voie à suivre: -
namespace YourNamespace
{
static class Program
{
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
HandleException(e.Exception);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleException((Exception)e.ExceptionObject);
}
static void HandleException(Exception e)
{
//Handle the Exception here
}
}
}
Dans ASP.NET, vous pouvez capturer toutes les exceptions non gérées en utilisant l'événement Application_OnError dans le Global.asax ou en accrochant à la demande Evénement .OnError avec votre propre HttpModule.
Vous pouvez également utiliser l'un de ces gestionnaires d'exceptions tiers.
ELMAH prend en charge les applications ASP.NET
http://code.google.com/p/elmah/
Exceptioneer (Nous construisons ce - juste mon signalement d'intérêt dans la région) prend en charge ASP.NET, les applications de la console, Windows Forms appliactions, Applications WPF etc.
http://exceptioneer.com/
Son extension VSTO - Extension d'application – shahjapan
Vous devriez jeter un oeil à CodeSmith Insight (http://www.codesmithtools.com/product/insight) Il offre une tonne de fonctionnalités et est le meilleur produit pour gérer les exceptions et répondre à votre base d'utilisateurs. –