请求超时时捕获数据

时间:2012-02-17 09:58:25

标签: asp.net web-services file-upload timeout ashx

我在ashx页面上获得了很多超时,该页面处理我的网络应用程序中的文件上传。有没有办法可以捕获超时并记录一些有关上传的数据,以帮助我更好地了解问题所在?

记录器看起来像这样,我只需要将它附加到超时异常!

Private Sub LogTimeoutException(context As HttpContext)
    'Gather the data
    Dim sb As New StringBuilder()
    sb.AppendLine(String.Format("Toal files: {0}", context.Request.Files.Count))
    For Each f As HttpPostedFile In context.Request.Files
        sb.AppendLine(String.Format("{0} ({1}): {2}", f.FileName, f.ContentType, f.ContentLength))
    Next

    'Log it
    Dim l As New BitFactory.Logging.FileLogger(context.Server.MapPath("~/timeoutlog.txt"))
    l.LogInfo(sb.ToString())
End Sub

1 个答案:

答案 0 :(得分:0)

尝试捕获的任何原因都不起作用?

Private Sub LogTimeoutException(context As HttpContext)
    Dim sb As New StringBuilder()
    Try
        //gather the data
        sb.AppendLine(String.Format("Toal files: {0}", context.Request.Files.Count))
        For Each f As HttpPostedFile In context.Request.Files
            sb.AppendLine(String.Format("{0} ({1}): {2}", f.FileName, f.ContentType, f.ContentLength))
        Next
    Catch he As HttpException    
        //Log it
        Dim l As New BitFactory.Logging.FileLogger(context.Server.MapPath("~/timeoutlog.txt"))
        l.LogInfo(sb.ToString())
    End Try
End Sub