'书写日志的程序
?'username :用户信息(标示进行该操作的人员)
'operate :操作(标示用户进行了什么操作)
'userip :用户ip(标示用户用于登录系统的计算机的ip地址)
'opdate :用户操作发生的日期
'日志写入一个xml文件,第一次写入时如果xml文件不存在,则创建。 '返回值:0 表示输入的参数无效 '返回值:1 表示打开日志文件时出错 '返回值:9 表示正确完成写入日志文件
?function writelog(username,operate,userip,opdate)
if username="" or operate="" or userip="" or opdate="" then
writelog=0 '参数无效
exit function
end if
rootnode="syslog"
'日志文件根节点名字
logfile=server.mappath("uuu.xml") '日志文件路径
set fso=server.createobject("scripting.filesystemobject")
'如果日志文件不存在,就创建一个,并写入头信息和根信息
if not fso.fileexists(logfile) then
fso.createtextfile logfile
set fff=fso.getfile(logfile)
set mmm=fff.openastextstream(2)?
mmm.write "《?xml version=""1.0"" encoding=""gb2312"" ?〉" & vbcrlf & "《" & rootnode & "〉《/" & rootnode & "〉"
set mmm=nothing
set fff=nothing
else
response.write("文件名冲突!")
response.end
end if
set fso=nothing
set xd = server.createobject("msxml2.domdocument")
xd.async = false xd.load(logfile)
if xd.parseerror.errorcode<>0 then
writelog=1 '打开日志文件出错
exit function
end if
'创建新节点信息
set et=xd.documentelement
set cnode=xd.createelement("log")
et.appendchild(cnode)
set node2=xd.createelement("username")
node2.text=username
cnode.appendchild(node2)
set node2=xd.createelement("operate")
node2.text=operate
cnode.appendchild(node2)
set node2=xd.createelement("userip")
node2.text=userip
cnode.appendchild(node2)
set node2=xd.createelement("opdate")
node2.text=opdate
cnode.appendchild(node2)
xd.save logfile '写入日志文件
set cnode=nothing
set node2=nothing
set xd=nothing
writelog=9 '说明正常写入了日志信息
end function