0
我的web服務中有一個被忽略的異常事件的小問題。ASP.NET Web服務忽略Application_Error和UnhandledException事件
這是我的Global.asax.cs文件:
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace AcmeDemoApp
{
public class Global : System.Web.HttpApplication
{
private static Logger logger = LogManager.GetCurrentClassLogger();
protected void Application_Start(object sender, EventArgs e)
{
logger.Debug("Application_Start");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
protected void Session_Start(object sender, EventArgs e)
{
logger.Debug("Session_Start");
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
logger.Debug("Application_BeginRequest");
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
logger.Debug("Application_AuthenticateRequest");
}
protected void Application_Error(object sender, EventArgs e)
{
logger.Debug("Application_Error");
}
protected void Session_End(object sender, EventArgs e)
{
logger.Debug("Session_End");
}
protected void Application_End(object sender, EventArgs e)
{
logger.Debug("Application_End");
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
logger.Debug("CurrentDomain_UnhandledException");
}
}
}
後,我執行請求。我從Web服務中得到這個錯誤。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: Error
--- End of inner exception stack trace ---</soap:Text>
</soap:Reason>
<soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
而在NLOG的日誌文件,我只看到:
[2016-05-01 02:11:25.3629] [Info] Application_BeginRequest
[2016-05-01 02:11:27.3861] [Info] Application_AuthenticateRequest
爲什麼UnhandledException忽略? 是否還有其他事件或方法我必須用來獲取所有soap
錯誤?
或者你能給我一個提示如何解決這個問題?
先謝謝您的任何想法!
嘗試處理Application.ThreadException – VladL
No @VladL我沒有'Application.ThreadException'。 'Application'存在,但沒有'ThreadException'事件/屬性。 – Patrick