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.CurrentDomain.UnhandledException += (s, e) =>
{
var 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With