ASP Logging Program

Source: Internet
Author: User
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











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.