View Full Version : Log File/Log history
Hi All,
Pls does anyone have a sample code or reference on how to create a Log File/history, for example in an Application, who login? what time? what did he do? but either a flat file is created to keep log history or the log history goes to a table in a Database. Really need help.
Abd
What do you mean by
but either a flat file is created to keep log history or the log history goes to a table in a Database
Don't you want it to be in a file/db or is that just what you want? Most of this information, you can get out of the webservers log. The "AppendToLog" method lets you add info to the webservers log. There its comma delimited, so you can import it into a db.
Personally, if it's important to you, i'd write it straight to the db. When they log in and out or when the session is destroyed. (When you validate there password against a db, it easy to update there record and append or update a variable with the logintime) Idem for when they log out.
If you wan't to track all pageviews, use the counter component.
If you want to register and analyse this for each individual user (= identify the usersaction) and you dont' have acces to the webservers logfile, i'd suggest you use cookies and store it all clientsided while the session is active, and then pick it up if they logout. It's absolutely not safe (don't mean securitywise, but because there's a real chance of dataloss if the just close there browser or timeout) but storing it in a sessionvariable, or writing it to the db or a textfile for each pageview, will take up quite some resources.
And if it's that important, you should have access to the logfiles.
So it really depends on how impoprtant it is to you and how many resources you wan't to spend on it.
Hi raf,
yeah I don't mind having the lof file in db, can I get a sample code or a ref site for such?
Thanks
Abdul
:confused:
Sample code or ref about what?
Hi raf,
I mean a sample code on how to create a Log File or Log History, you mentioned using AppendToLog, can I see a sample code on that or any other Log File creation using ASP.
Thanks
Abd
Don't think this is all clear.
IIS automatically keeps a log of all requests (pages that a client requested). You can append additional info to this IIS. More info below.
Or you can decide to register all requested pages in a db. But this means you either need to write a record (or update a record) with each page that a user requests. Or you need to do the same with a textfile or session-variable. Either method will take up some resources from the webserver. If there is a lott of traffic, it could substantially influence the responsetimes
So i'd advice only registering things that are important enough + if you're really gonna do anythng with it. (Like the login or logout time.). You can create a seperate table where you insert a record after the user logged in. If he logs out, you update that record.
Like this
when login
sql= "INSERT INTO logtable (session,username, logintime) VALUES (" & Session.SessionID &",'username',#" & Now & "#)"
when logout
sql="UPDATE logtable SET logouttime=#" & Now & "# WHERE session=" & Session.SessionID
Info from helpfile
---------------------------------------
AppendToLog
The AppendToLog method adds a string to the end of the Web server log entry for this request. You can call it multiple times in one section of script. Each time the method is called it appends the specified string to the existing entry.
Syntax
Response.AppendToLog string
Parameters
string
The text to append to the log file. Because fields in the IIS log are comma-delimited, this string cannot contain any comma characters (,). The maximum length of this string is 80 characters.
Remarks
In order for the specified string to be recorded in the log file, you must enable the URI Query option of the Extended Logging Properties sheet for the site whose activity you wish to log. For more information on configuring Extended Logging, see Customizing W3C Extended Logging.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.