application level error catch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a straight forward way to tell .net to log any unhandled errors in
the application log. I am catching and logging in certain locations but its
the surprise errors that I need to log the information from. I know how to
log using a try-catch block but i need something for any unforseen error
since my users do not report the description and location correctly.

Thanks for any help.
 
Thanks Patrice, but I am using a windows application not a web app. I
thought any errors not handled would get written to the event viewer but they
do not. For instance at some random place I get a connection timeout or an
input error, etc. I would like to be able to record that somewhere.

Thanks
 
Subscribe to the Appdomain.UnhandledException event and log it from there.
If you do not handle it then you get the default behavior of the runtime,
which does not log it. For a windows app or asp.net you will also need to
subscribe to the Application.ThreadException and the
Web.HttpApplication.Error event to get all exceptions.

In general you should write the code so you never get a UE. In the shipping
version of the runtime (v1.1) a UE does not cause the app to terminate; in
future versions the app will terminate after a UE has been processed.
 
Back
Top