Author | Message | Time |
---|---|---|
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:[code]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[/code] Any solutions? | March 19, 2004, 8:38 AM |
LoRd | 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. | March 19, 2004, 8:49 AM |
Dyndrilliac | Thanks, worked beautifully. | March 19, 2004, 8:55 AM |
R.a.B.B.i.T | You should use: [code] 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 [/code] | March 20, 2004, 12:42 AM |
o.OV | [quote author=R.a.B.B.i.T link=board=31;threadid=5869;start=0#msg50517 date=1079743341] You should use: [code] 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 [/code] [/quote] I wouldn't even use a check for that and I would Open for Append. [code] Dir$(LogLocation) = "" 'should be LenB(Dir$(LogLocation)) 'and Print #1, "" 'would be simpler as Print #1, [/code] | March 20, 2004, 1:23 AM |