有没有办法像在ASP.NET网站中一样使用ELMAH在常规ASP.NET Web服务(asmx)中全局处理异常?
最佳答案
ASP.NET Web服务从不触发Application_Error
事件,并且ELMAH无法像在ASP.NET应用程序中那样全局处理异常。但是我们可以使用ELMAH“手动”记录异常:
public int WebServiceMethod() {
try {
...
}
catch (Exception ex) {
Elmah.ErrorLog.GetDefault(
HttpContext.Current).Log(new Elmah.Error(ex, HttpContext.Current));
}
}
关于asp.net - 使用Elmah处理Web服务中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2180228/