There's various ways of doing this, the following may not necessary be the best, but its what i'm using at the moment. I have a general routine...
Code:
Public Sub AddToLogFile(ByVal LogFileDirectory As String, ByVal Message As String)
Dim FSW As System.IO.StreamWriter
FSW = New System.IO.StreamWriter(LogFileDirectory & "\ExceptionLog.log", True)
FSW.WriteLine("--------------------------------------------------------------------------------")
FSW.WriteLine(Now.ToLongDateString & ", " & Now.ToShortTimeString)
FSW.WriteLine(Message)
FSW.Close()
End Sub
I use this to record errors with the web site, so it records the date the entry was added.
I call it using something like...
Code:
Dim Loc As String
Loc = WebPage.Request.PhysicalApplicationPath()
AddToLogFile(Loc, "An error has occurred")
Which will then append to the file "ExceptionLog.log" in the root of the web application directory. You can replace the path with any physical path.
Alternatives to this are...
Writing to the Windows event manager
Adding entries to a seperate database table.
The latter is worthwhile for recording login requests, since you can use queries to check on particular users for example, rather than sifting through a large text file.