Open and Append to a Log File
Imports System
Imports System.IO
Class DirAppend
Public Shared Sub Main()
Using w As StreamWriter = File.AppendText("log.txt")
Log("Test1", w)
w.Close()
End Using
Using r As StreamReader = File.OpenText("log.txt")
DumpLog(r)
End Using
End Sub
Public Shared Sub Log(logMessage As String, w As TextWriter)
w.WriteLine(logMessage)
w.Flush()
End Sub
Public Shared Sub DumpLog(r As StreamReader)
Dim line As String
line = r.ReadLine()
While Not (line Is Nothing)
Console.WriteLine(line)
line = r.ReadLine()
End While
r.Close()
End Sub
End Class
Related examples in the same category