(Logfile) - In most every program I have written lately, i've had a
need to keep a log file of user activities. This was a challenge for
me at first, but the thing that makes this code a LOT easier on you is
if you understand the "Settings" feature. In the code below, I've
setup a my.settings string named "logloc" (Log File Location) that
points to the directory where my logfile exist (C:\program\log.txt)
then the code creates a virtual textbox, reads the logfile, then
appends the (VT) or whatever I wish to add to the log at the TOP of
the logfile, then creates a new line, so that when I view the log
file, the newest entry is at the top.
If you need more help with this code, let me know and I'll be happy to
help you configure it to your needs.
-------------------------
Dim myfile As String = My.Settings.logloc
Dim itxt As New TextBox
If IO.File.Exists(myfile) Then
itxt.Text = IO.File.ReadAllText(myfile)
End If
Dim vt As String = vbCrLf & Date.Now & " - " &
My.Application.Info.Version.ToString & ex.ToString & My.User.Name &
itxt.Text
My.Computer.FileSystem.WriteAllText(myfile, vt, False)
itxt.Clear()
--------------------------