我有下面的代码适用于我,并在我的Web应用程序的“错误应用程序”事件中使用。但是,我有一个运行时错误,设法逃避此代码:
“事件代码:4010事件消息:发生了未处理的安全异常。”
这意味着我没有堆栈跟踪,这让我可以看到导致此问题的原因。如何修改我的代码以捕获此运行时错误?
public void AddLogEntry(HttpRequest httpRequest, Exception ex)
{
LogData.LogEntry entry = new LogData.LogEntry();
//PageTitle
entry.PageTitle = httpRequest.Url.AbsolutePath;
//Date
entry.Created = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
// httpRequest
//Error
entry.Error = ex.ToString();
//HTTP-Values
foreach (string key in httpRequest.ServerVariables)
{
string value = httpRequest.ServerVariables[key];
if (value != string.Empty)
{
if (key == "ALL_HTTP" || key == "ALL_RAW")
value = value.Replace(System.Environment.NewLine, ", ");
entry.ServerVariables.Add(key + ": " + value);
}
}
if (_data.LogEntries.Count > 500)
_data.LogEntries.Clear();
_data.LogEntries.Add(entry);
//Send e-mail to developers
SendEmail(entry.ToString());
}