Add to Favorites    Make Home Page 14381 Online  
 Language Categories  
 Our Services  

Home » ASP Home » Files Home » Create and Write Log File

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title 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.
Category ASP » Files
Hits 380857
Code Select and Copy the Code
<% 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 %>

Related Source Codes

Script Name Author
��������������������� VyomWorld
Resistor color code reader A.Chermarajan.
Telephone Directory dhivya
card swapping game (Mini Project) nityanand
simple hangman-pascalsource Seabert
college dirtectory (Mini Project) msridhar
Poll Application John van Meter
ASP Daily Hit Counter. Tejaskumar Gandhi
To avoid null in asp environment using sql Sami
Maklumbalas webmaster
poll John van Meter
EasyASP Template Engine. TjoekBezoer
Basic Calculator using HTML & Javascript. Patrick M. D Souza
What servers support ASP ? VyomWorld
What is ASP? VyomWorld

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=330


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review