处理与ELMAH Web服务异常 [英] Handle exceptions in web services with Elmah

查看:88
本文介绍了处理与ELMAH Web服务异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在全球范围使用ELMAH常规ASP.NET Web服务(ASMX)处理异常就像我们在ASP.NET网站做呢?

Is there a way to globally handle exceptions in regular ASP.NET Web Service (asmx) using ELMAH like we do it in ASP.NET web site ?

推荐答案

ASP.NET Web服务从来没有火的Application_Error 事件和异常无法通过全球在ELMAH处理ASP一样.NET应用程序。但是,我们可以在手动登录使用ELMAH异常:

ASP.NET web services never fire Application_Error event and exceptions cannot be handled globally by ELMAH like in ASP.NET apps. But we can "manually" log exceptions using ELMAH:



public int WebServiceMethod() {
  try {
   ...
  }
  catch (Exception ex) {
    Elmah.ErrorLog.GetDefault(
      HttpContext.Current).Log(new Elmah.Error(ex, HttpContext.Current));
  }
}

这篇关于处理与ELMAH Web服务异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆