• Welcome to Valhalla Legends Archive.
 

Need Help With Logging System

Started by Dyndrilliac, March 19, 2004, 02:38 AM

Previous topic - Next topic

Dyndrilliac

I'm creating a WebServer and for the most aprt everything works fine, just my logging system doesn't.

Basically I wan't it to Append to a text file the person's IP address and File They Requested - Now, I've got it doing all of this, except when someone goes to the site they replace the last person who went there before them, so it isn't really logging traffic, it's logging the person who's there at that moment before someone else shows up - and when you get 50-60 hits within 5 minutes that's pretty much useless.

Here's what I'm doing. I'm putting the following code into the DataArrival part of my Winsock control:Dim LogLocation As String
LogLocation = websitedir & "Log.txt"

Open LogLocation For Output As #1 ' Makes sure the file exists
Close #1

Open LogLocation For Append As #2
Print #2, "File Requested: " & a
Print #2, "IP: " & ws(Index).RemoteHostIP
Print #2, "----------------------------------------"
Print #2, ""
Close #2


Any solutions?
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Eric

#1
Don't open the file for output before appending.  Append will check to see if the file exists before writing to it, if the check fails the file will be created.

Dyndrilliac

Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

R.a.B.B.i.T

#3
You should use:

If Dir$(LogLocation) = "" Then
   Open LogLocation For Output As #1
Else
   Open LogLocation For Append As #1
End If
Print #1, "File Requested: " & a
Print #1, "IP: " & ws(Index).RemoteHostIP
Print #1, "----------------------------------------"
Print #1, ""
Close #1

o.OV

Quote from: R.a.B.B.i.T on March 19, 2004, 06:42 PM
You should use:

If Dir$(LogLocation) = "" Then
   Open LogLocation For Output As #1
Else
   Open LogLocation For Append As #1
End If
Print #1, "File Requested: " & a
Print #1, "IP: " & ws(Index).RemoteHostIP
Print #1, "----------------------------------------"
Print #1, ""
Close #1


I wouldn't even use a check for that
and I would Open for Append.


Dir$(LogLocation) = ""
'should be
LenB(Dir$(LogLocation))
'and
Print #1, ""
'would be simpler as
Print #1,
If the facts don't fit the theory, change the facts. - Albert Einstein