Program ' Writing log program
?' Username: User information (identifies the person who performed the operation)
' operate: action (to indicate what the user did)
' userip: User IP (the IP address of the computer that identifies the user used to log on to the system)
' opdate: Date the user action occurred
' log writes an XML file that is created the first time it is written if the XML file does not exist. ' Return value: 0 indicates invalid parameter ' return value: 1 Error opening log file ' return value: 9 indicates that the write log file was completed correctly
function Writelog (username,operate,userip,opdate)
if Username= "" or operate= "" or userip= "" or opdate= "" then
Invalid
writelog=0 ' argument
Exit Function
End If
rootnode= "Syslog"
' log file root node name
Logfile=server.mappath ("uuu.xml") ' Log file path
set Fso=server. CreateObject ("Scripting.FileSystemObject")
' If the log file does not exist, create one and write header and root information
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 ("filename conflict!") ")
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 ' Open log file error
Exit Function
End If
' Create new node information
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 ' write to log file
Set cnode=nothing
Set node2=nothing
Set xd=nothing
writelog=9 ' Description writes the log information normally
End Function