Capture all unhandled exceptions automatically with WebService

后端 未结 3 874
清歌不尽
清歌不尽 2021-01-13 10:23

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

How can I do this?

相关标签:
3条回答
  • 2021-01-13 10:48

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

    PostSharp

    Spring.Net

    0 讨论(0)
  • 2021-01-13 10:52

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

    0 讨论(0)
  • 2021-01-13 11:01

    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?
    0 讨论(0)
提交回复
热议问题