gpt4 book ai didi

asp.net - 如何忽略全局 asax 中图像的日志记录错误

转载 作者:行者123 更新时间:2023-12-02 10:26:28 25 4
gpt4 key购买 nike

我的 global.asax 中有一个错误处理程序,如下所示;

  Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim ex = Server.GetLastError.GetBaseException
Dim lastErrorWrapper As HttpException = Server.GetLastError()
Dim lastError As Exception = lastErrorWrapper

If lastErrorWrapper.InnerException IsNot Nothing Then
lastError = lastErrorWrapper.InnerException
End If

My.ErrorHandler.LogError( _
"<BR/><BR/>URL: " & Request.RawUrl & _
"<BR/><BR/>STACK: " & ex.StackTrace & _
"<BR/><BR/>SOURCE: " & ex.Source & _
"<BR/><BR/>MESSAGE: " & ex.Message & _
"<BR/><BR/>TYPENAME: " & ex.GetType.ToString & _
"<BR/><BR/>INNER EXCEPTION: " & lastError.ToString & _
"<BR/><BR/>REFERRER: " & HttpContext.Current.Request.Url.AbsoluteUri & _
"<BR/><BR/>USER IP: " & Request.ServerVariables("REMOTE_ADDR") & " -- " & Request.ServerVariables("HTTP_USER_AGENT"))
End Sub

显然,这非常有效,只要出现错误就会向我发送电子邮件。但是,对于文件系统中找不到的任何图像也是如此。它给我一个“文件不存在”。错误。有没有办法忽略不在磁盘上的图像的日志记录错误?

最佳答案

您不能解决 FileNotFoundException 问题吗?如果异常不应该发生,那么宁愿解决问题而不是抑制它。要处理已知异常,您可以使用以下代码。

if(Server.GetLastError().GetBaseException() is System.Web.HttpException)
{
//You could check whether the
//Server.GetLastError().GetBaseException().Message contains the appropriate message
Debug.WriteLine("Suppressed FileNotFoundException");
}else
//Log an unhandled exception

关于asp.net - 如何忽略全局 asax 中图像的日志记录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13928420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com