【发布时间】:2016-05-01 00:15:28
【问题描述】:
我的网络服务中有一个被忽略的异常事件的小问题。
这是我的 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");
}
}
}
在我执行请求之后。我从网络服务收到此错误。
<?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 我没有
Application.ThreadException。Application存在但没有ThreadException事件/属性。
标签: c# asp.net nlog global-asax unhandled-exception