123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
Create and Write Log File

--------------------------------------------------------------------------------

Description : The subprocedure can be called by any ASP applicaiton/page which needs to create a log entry each time it is accessed. This can then be checked at a later stage by an administrator for example, to determine who/how/when details concerning a given application/ASP page. As it stands at the moment the log subprocedure records the data&time, client IP address, and path of the application/page which called the function to each entry made in the log file.

<%
Sub WriteToLog(strUserLogFileName)

'WriteToLog is a simple asp subprocedure
' .
'Allows log entry (details of the log en
' try can be altered/user defined see belo
' w) to be written to
'a log file(user defined name passed by
' parameter string to the subprocedure) ea
' ch time the function is called
'from an .asp page. The .asp should incl
' ude this function via an '#include file=
' "WriteToLog.asp"
'statement at the top of the .asp script
' file.
'The path of the log file is that of the
' parent page where the function has been
' included.
'The user must pass in a parameter, strU
' serLogFileName, which is then converted
' to
'strUserLogFileName.log. Thus this becom
' es the file name of the log file saved i
' n the parent
'folder of the WriteToLogFunc.asp functi
' on.
'NOTE: NOT ON BRINKSTER!!- DIRECTORY OF
' LOG FILE MUST BE DB FOR SECUIRITY REASON
' S
'IF YOU TEST THIS FUNCTION ON BRINKSTER,
' YOU MUST CHANGE THE CODE AS OUTLINED BEL
' OW
'ESSENTIALLY CHANGE THE PATH OF THE LOG
' FILE TO THE DB DIRECTORY
'A string parameter without a file exten
' tion should be passed to this function.
'As this file is intended to be an #incl
' ude file: The statements Option explicit
' and the
'@Language=VBScript have not be placed i
' n the header, this resloves problems ass
' ociated
'with misplacements & repetition of thes
' e statements once the file is included
'this can cause run time errors.
Const ForAppending=8
Dim strLogFileName, strFolderPath, strPhysicalPath,strLogEntryTime
Dim objFSO,objApplicationFolder,objApplicationFile,objLogFileFSO,objLogFileTransaction

Set objFSO=CreateObject("Scripting.FileSystemObject")

'First retrieve the parent directory path where the LogFile
'is kept

strPhysicalPath=Server.MapPath(Request.ServerVariables("PATH_INFO"))
Set objApplicationFile=objFSO.getFile(strPhysicalPath)
Set objApplicationFolder=objApplicationFile.ParentFolder
strFolderPath=objApplicationFolder.path
'create the String path To the log file within the parent directory
'of this application,
'NOTE: For BRINKSER YOU HAVE STORE THE FILE IN THE db DIRECTORY
'So the code To generate path String will be: strLogFileName=strFolderPath+"db"+strLogFileName

strLogFileName=strUserLogFileName+".log"'Generate the correct filename With extension
strLogFileName=strFolderPath+""+strLogFileName 'Generate the full path String


'create/open log file FileSystemObject
Set objLogFileFSO=CreateObject("Scripting.FileSystemObject")
'test whether file exists To either write/append to file
If objLogFileFSO.FileExists(strLogFileName) Then
Set objLogFileTransaction=objLogFileFSO.OpenTextFile(strLogFileName,ForAppending)
'FOR BRINKSTER the above line should be:
' Set objLogFileTransaction = objFSO.OpenTextFile((Server.MapPath("/YOURUSERAREANAME/db/"+strLogFileName)),ForAppending)
Else
Set objLogFileTransaction=objLogFileFSO.CreateTextFile(strLogFileName)
'FOR BRINKSTER the above line should be:
'
'Set objLogFileTransaction = objFSO.Crea
' teTextFile((Server.MapPath("/YOURUSERARE
' ANAME/db/"+strLogFileName)))
End If
'THE FOLLOWING LINE DISPLAYS STORED LOG FILE NAME AND PATH, AND CAN BE COMMENTED OUT!
Response.Write "<BR>FROM WriteLogFunc: " & strLogFileName &"<BR>"

strLogEntryTime=Now

'This is where the actual log data is written,
'alter anything below To alter the data to be entered into the log file
'chr(9) is a VB tab character, which makes the log file easier To read.
'At the moment it's simply the Date and time the .asp script was accessed, the IP address of
'the client, and the name of the file which generated the log entry To be written.
'The last entry allows a Single log file To be written to by various .asp scripts, and allow the origin
'of Each entry To be determined.
objLogFileTransaction.WriteLine strLogEntryTime & Chr(9) &_
Chr(9) & (Request.ServerVariables("HTTP_X_FORWARDED_FOR")) &_
Chr(9) & strPhysicalPath

objLogFileTransaction.Close
'ensure that all memory is unallocated once log entry has been created
Set objLogFileTransaction=Nothing
Set objLogfileFSO=Nothing
Set objFSO=Nothing
Set objApplicationFile=Nothing
Set objApplicationFolder=Nothing
End Sub
%>
-------------------------------------------------------------------------------

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG