Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Dyndrilliac on March 19, 2004, 02:38 AM

Title: Need Help With Logging System
Post by: Dyndrilliac on March 19, 2004, 02:38 AM
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?
Title: Re:Need Help With Logging System
Post by: Eric on March 19, 2004, 02:49 AM
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.
Title: Re:Need Help With Logging System
Post by: Dyndrilliac on March 19, 2004, 02:55 AM
Thanks, worked beautifully.
Title: Re:Need Help With Logging System
Post by: 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
Title: Re:Need Help With Logging System
Post by: o.OV on March 19, 2004, 07:23 PM
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,