不使用 try/catch 自动记录未处理的异常

发布于 2024-08-05 10:49:02 字数 385 浏览 4 评论 0原文

因此,我希望能够将所有未处理的异常记录到事件日志中,而不必手动捕获所有异常并将其写出。

我想在 WCF 服务中使用运行状况监视功能,问题是这只能捕获由 asp.net 生成的错误,而且我特别想捕获调用 SharePoint 时引发的 SPException 错误。

似乎只有在调用 System.Management 命名空间中的 WebBaseErrorEvent 上的 raise 方法时才会处理异常,我假设 ASP.Net 异常本质上会执行此操作,但 SPException 不会。因此,我唯一的选择是手动捕获 SPException 错误并将其写入事件日志,或者创建一个新的 WebBaseErrorEvent 对象并对其调用 raise,这违背了我想要实现的目标。

我错过了什么吗有更简单的方法吗?

So I want to be able to just log all unhandled exceptions to the event log without having to catch all the exceptions manually and write them out.

I wanted to use the health monitoring functionality within a WCF service, the problem is that this only catches errors generated by asp.net and I specifically want to also catch SPException errors thrown from calling into SharePoint.

It seems that exceptions are only handled if they call the raise method on the WebBaseErrorEvent in the System.Management namespace, I assume ASP.Net exceptions do this inherently but SPExceptions do not. So my only option is the manually catch SPException errors and write them out to the event log or create a new WebBaseErrorEvent object and call raise on it which defeats what I want to achieve.

Am I missing something is there an easier way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸 2024-08-12 10:49:02

看了 ELMAH

我知道你的在堆栈中更深入一些,但这些不会来吗通过?

说实话,关于 SPException 的更多内容超出了我的理解范围,但我会留下 博客值得注意。 认为有人有一个叫sharepoint例外的博客!

感谢 @Alex 在评论中指出了这个问题

Looked at ELMAH

I know yours are a little more deep down the stack but would these not come through?

TBH, any more with regard SPException is beyond my ken, but will leave blog of note. To think someone has a blog called sharepoint exception!

And credit to @Alex for pointing out this question in comments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文