Capture all unhandled exceptions automatically with WebService

こ雲淡風輕ζ 提交于 2019-12-19 08:31:13

问题


I have a C# WebService application in which I want to capture all unhandled exceptions thrown from the application.

How can I do this?


回答1:


For some reason the Application_Error event does not fire for Web Services (see other question). Mr Jeff Atwood himself has posted some advice on the coding horror blog.

He writes:

* Put a try..catch around every WebService method. These methods tend to be wrappers around other classes, so this isn't quite as bad as it sounds, but it's still not good.
* use a Facade design pattern to derive all objects from parent objects that.. basically do a try..catch on the .Execute method. Uh, thanks but no thanks.
* Write a custom SOAP Extension or HttpModule. This sounds reasonable but.. hard. If it's such a cool, important extension or HttpModule, wouldn't someone have written it already?



回答2:


One way will be to subscribe to AppDomain.UnhandledException event somewhere in App_Start handler.




回答3:


Perhaps a job for an aspect-oriented approach. Some examples;

PostSharp

Spring.Net



来源:https://stackoverflow.com/questions/829086/capture-all-unhandled-exceptions-automatically-with-webservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!