Hi,
Is there any easy way to auto write all the unhandled exception in my application to a log file? I`m using log4net as my logging solution.
My application hosted as a windows service.
Thanks.
Hi,
Is there any easy way to auto write all the unhandled exception in my application to a log file? I`m using log4net as my logging solution.
My application hosted as a windows service.
Thanks.
It depends on the type of application you are running. You should always register the AppDomain.UnhandledException
event during startup of your application:
AppDomain.Current.UnhandledException += (s, e) =>
{
Exception exception = (Exception)e.ExceptionObject;
// Log to log4net.
});
When using a ASP.NET application, you can hook onto the HttpApplication.Error
event use the Global.asax to do this. When using a Windows Forms application you can hook onto the Application.ThreadException
event.
Good luck.