I have a VB.NET application that writes status to a log file in text format. Over time, the file becomes large, and I would like to know if there is an effective way to truncate the beginning of the file.
To simplify the task, I want to specify the file size (say, 2-3 mb), and I write the log using StreamWriter:
Using strm As New IO.StreamWriter(filelocation.log, True)
strm.WriteLine("msg to write")
strm.Close()
End Using
I thought about using strm.BaseStream.Lengthit to determine which part of the file was cut, but with the help of .SetLengthit it will cut from the end - not the desired result.
source
share