经典asp中的异步日志记录

时间:2011-05-04 02:05:21

标签: asp-classic

对于我在IIS6.0中部署的经典asp应用程序,我需要异步地将日志记录错误实现到文本文件,以便日志记录将应用程序与日志记录资源分离,从而允许应用程序在底层日志记录基础结构因任何原因变得不可用时继续运行。我在其中一个回答中读到了可以使用xmlhttp的类似问题。还有其他方法吗?请帮忙

2 个答案:

答案 0 :(得分:0)

您想记录哪些错误?

ASP错误?然后你必须使用ON ERROR RESUME NEXT运行所有代码+在每个站点上写一个错误处理程序。那些例如您可以通过SSI包含在所有页面上。

由于经典的asp是单元线程模型,所以你不能真正地异步执行此操作!但是你可以写一个COM +组件。这个组件有一个方法,然后你传递err.number,description,source(+可能是Request.ServerVariables(“URL”))ByVal,然后快速返回。在组件内部,您可以启动异步线程来编写日志文件或将错误写入任何数据库。

不确定这是否是您正在寻找的,但如果是这样,那就是您可以这样做的方式。

答案 1 :(得分:0)

并非完全符合您的要求,但这是适用于Chrome的ASP经典日志记录解决方案,可提供与javascript console.log()等相当一致的体验。 日志记录将JS注入响应并登录到开发人员控制台(F12) 单元测试和样本使用-内部 注意事项:避免出现“脚本中的脚本”情况

<%

' log from ASP lines to chrome dev console - using the same javascript syntax
' ref: https://developers.google.com/web/tools/chrome-devtools/console/api#dir

' to add this to your asp page:
' <!--#Include file ="log.asp"-->

' sample usage - see unit test at bottom

' to turn logging ON, you have those options:
'  console.active = true
'  run on localhost
'  add queryString log=1  (e.g. www.myweb.com?log=1)


class oConsole
    private isActive
    private oGroup
    private mGroupLabel
    private mGroupType
    Private Sub Class_Initialize(  )
        isActive = (Request.ServerVariables("SERVER_NAME") = "localhost") or _
                   (request.queryString("log") = "1") or _
                   session("log")
        set oGroup = nothing
    end sub

    Public Property Let active(a)
        isActive = a
        session("log") = cBool(a)
    End Property

    public property get active
      active = isActive
    end property

    private sub script(func, text)
        if not isActive then exit sub
        text = replace(text, """", "\""")
        if not oGroup is nothing then
            oGroup.add oGroup.count, func & "(""" & text & """)"
        else
            Response.Write "<script language=javascript>console." & func & "(""" & text & """)</script>" & vbCrLf
        end if
    end sub

    public sub log(Text)
        script "log", Text
    end sub

    public sub Warn(w)
        script "warn", w
    end sub

    public sub error(e)
        if e = "" then e = "Error 0x" & hex(err.number) & " " & err.description
        script "error", e
    end sub

    public sub assert(cond, message)
        if not cond then script "assert", """,""" & message
    end sub

    public sub logVar(Variable)
        log Variable & "=" & eval(Variable) 
    end sub

    public sub clear
        if not isActive then exit sub
        response.write "<script language=javascript>console.clear()</script>"  & vbCrLf
    end sub

    public sub group(label)
        set oGroup = CreateObject("Scripting.Dictionary")
        mGroupLabel = label
        mGroupType = "group"
    end sub

    public sub groupCollapsed(label)
        group label
        mGroupType = "groupCollapsed"
    end sub

    public sub groupEnd
        if isNull(oGroup) then exit sub
        Response.Write "<script language=javascript>" & vbCrLf
        response.write "console." & mGroupType & "(""" & mGroupLabel & """)" & vbCrLf
        dim X
        for each X in oGroup
            response.write "console." & oGroup.item(X) & vbCrLf 
        next
        response.write "console.groupEnd()" & vbCrLf
        response.write "</script>" & vbCrLf
        set oGroup = nothing
    end sub

end class

dim console
set console = new oConsole


sub logTest
    if not console.active then
      console.active = true
      console.clear 
      console.warn "logging activated for testing"
    else
        console.clear       
    end if
    console.log "hello "
    console.warn "warning"
    console.error "error"
    console.assert true, "should not see this"
    console.assert false, "Assertion"
    on error resume next
    f=1/0
    console.Error "" ' logs the Err object
    on error goto 0
    console.logVar "now"
    console.groupCollapsed "My collapsed group"
        console.log "L1"
        console.warn "W1"
        console.error "E1"
    console.groupEnd
    console.group "My group"
        console.log "L1"
        console.warn "W1"
        console.error "E1"
    console.groupEnd
    console.active = false
    console.error "can't see this"
    console.active = true
    console.log "should see that"
end sub


%>

enter image description here