捕获请求超时数据

发布于 2025-01-06 17:20:47 字数 634 浏览 4 评论 0原文

我在处理网络应用程序中的文件上传的 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

I'm getting a lot of timeouts on an ashx page which handles file uploads in my web app. Is there a way I could capture the timeout and log some data about the upload to help me better understand what the problem is?

The logger would look something like this, I just need to attach it to a timeout exception!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2025-01-13 17:20:47

为什么 try catch 不起作用?

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

Any reason why a try catch wouldn't work?

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文