views:

831

answers:

5

I'm trying to use ASP.net health monitoring to log unhandled exceptions from an asmx web service. I've enabled health monitoring in the web.config but it's not logging anything. Does health monitoring work with asmx web services? I've googled around and seems other people have asked the same question but never got a definite answer.

A: 

It won't work because the unhandled exceptions are not running inside a try/catch of any kind. Because of that, it won't be able to log it. Take a look at this blog post: http://blogs.msdn.com/tom/archive/2007/12/04/unhandled-exceptions-causing-asp-net-to-crash-in-net-2-0.aspx

Tom
+1  A: 

There's a difference between the normal interpretation of unhandled exceptions, and those Tom are referring to. What Tom is referring to are truly unhandled exceptions, that will kill your w3wp.exe process (before it has a chance to log it), as I've blogged about here: http://www.improve.dk/blog/2008/04/07/spawning-threads-in-aspnet-can-be-dangerous

Normal unhandled exceptions will result in an exception ocurring and showing an error page to the user / callee. It will not however crash your w3wp.exe process. These exceptions should be picked up by the health monitoring.

Mark S. Rasmussen
A: 

the CALM product should work in this case; let me know if it doesn't - i wrote it ;-)

Steven A. Lowe
your product might work, but your link doesn't :)
frankadelic
@frankadelic: sorry about that, we're in the process of redoing the web site and changing hosting providers and everything is still down; drop me an email (steven dot lowe at nov8r.com) and I'll send you the installer if you want to try it
Steven A. Lowe
+1  A: 

In the Global.asax, if you use the one auto-generated by Visual Studio, you can add code to the Application_Error method to handle exceptions and log them in any way you choose. You can also override the Init method and add an event handler for the class's Error event.

In either case you only get an unhelpful vanilla EventArgs object, but you can use HttpContext.Current.Server.GetLastError() to get the exception that occurred.

As another poster mentioned, this may not catch exceptions that are thrown by asynchronously running delegates, threads you start yourself, or asynchronous page tasks creaeted using Page.RegisterAsyncTask(). On these you always need to make sure that the implementations have exception back-stops so that the exceptions can be caught and the IIS worker process does not get aborted.

David
+7  A: 

I just hate all of you random posters. Instead of helping you make people look the wrong direction. If you don't know the answer DON'T POST. Health monitoring has nothing to do with neither "really unhandled" ASP.NET exceptions nor the Application_Error event.

The answer is no. I have digged this a bit and for some reason exceptions raised within web methods never make it to the health monitoring providers. It looks like you have to catch them and handle yourself.

rciq
Yup. Most people just don't know what Health Monitoring is. There was a Microsoft Connect issue on this specific problem, but it was closed as 'By Design'. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=429373
ranomore