Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor a .Net server application for fatal exceptions?

I am developing a .Net server application, which is supposed to run continously. I would like to have a notification email sent each time the server process is terminated for any reason. Ideally the email should contain the exception message and stacktrace if an exception caused the termination. I am aware that certain exceptions can not be caught, such as StackOverflowException. So how would you log / send notification that a StackOverflowException occured in the server process?

I am thinking along the lines of creating a second process to monitor the server process. But how would that get the details of the exceptions occuring?

like image 407
shojtsy Avatar asked Jan 29 '10 23:01

shojtsy


People also ask

How to see exceptions in Application Insights?

Open the Application Insights Search telemetry window in Visual Studio. While debugging, select the Application Insights dropdown box. Select an exception report to show its stack trace.

Which of the following is the easiest way to track all unhandled error?

If your application has unhandled exceptions, that may be logged in the Windows Event Viewer under the category of “Application.” This can be helpful if you can't figure out why your application suddenly crashes. Windows Event Viewer may log two different entries for the same exception.

What is unhandled exception in c#?

An unhandled exception occurs when the application code does not properly handle exceptions. For example, When you try to open a file on disk, it is a common problem for the file to not exist. The . NET Framework will then throw a FileNotFoundException.


2 Answers

Fatal exceptions such as a StackOverflowException will usually result in an entry in the Windows event log (maybe even including the stacktrace). You can monitor your event log (e.g. with another service) that will send out an email on certain entries. A simple application for monitoring event log entries is described here:

A realtime event log monitoring tool

and here:

Send email alerts when errors are written to the event log

If you want your service to be continuously up and running you might want to configure it to restart automatically in case it crashed (although you should be aware that usually is a reason why it crashed and simply restarting does not necessarily remove that reason). You can do so on the Recovery tab under service properties. There you also have the option to call a custom program or script in case of a service crash.

Another option using built-in Windows features is to configure event log to send an email notification. This works at least from Windows Vista on, as described here:

How to Setup Event Viewer to Send a Email Notification in Vista

like image 73
Dirk Vollmar Avatar answered Oct 15 '22 09:10

Dirk Vollmar


Actually, you don't need any 3rd party software at all to do this - Win7 Task Scheduler can fire a scheduled task whenever it sees a certain type of event, and an unhandled exception is written to the Event Log. One of the built-in actions is "Send an Email", so you've got your whole solution in the OS

like image 21
Ana Betts Avatar answered Oct 15 '22 11:10

Ana Betts