【发布时间】:2020-06-18 20:07:50
【问题描述】:
对于部署在 IIS6.0 中的经典 asp 应用程序,我需要将错误日志记录异步写入文本文件,以便日志记录将应用程序与日志记录资源分离,从而允许应用程序在底层日志记录基础设施因任何原因变得不可用时继续运行。我读到了对可以使用 xmlhttp 的类似问题的回复之一。还有其他方法吗?请帮忙
【问题讨论】:
标签: asp-classic
对于部署在 IIS6.0 中的经典 asp 应用程序,我需要将错误日志记录异步写入文本文件,以便日志记录将应用程序与日志记录资源分离,从而允许应用程序在底层日志记录基础设施因任何原因变得不可用时继续运行。我读到了对可以使用 xmlhttp 的类似问题的回复之一。还有其他方法吗?请帮忙
【问题讨论】:
标签: asp-classic
您要记录哪些错误?
ASP 错误?然后,您必须使用 ON ERROR RESUME NEXT 运行所有代码 + 在每个站点上编写错误处理程序。那些例如您可以通过 SSI 包含在所有页面上。
因为只有经典的 asp 是单元线程模型,所以您不能真正异步执行此操作!但是您可以编写一个 COM+ 组件。该组件有一个方法,您可以在其中传递 err.number、描述、源(+ 可能是 Request.ServerVariables("URL")) ByVal,然后快速返回。在组件内部,您可以启动异步线程来写入日志文件或将错误写入任何数据库。
不确定这是否是您要寻找的东西,但如果是,那么您可以这样做。
【讨论】:
不完全是您所要求的,但这里有一个适用于 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
%>
【讨论】: