How to limit size of data file

I have a log file that I am adding error messages to as my application runs along, e.g. logfile.AppendText. I would like help on how I can limit the size of the file and possible delete the first stored line, when the file has reached it's max limit, so the new AppendText will add the error to end of the file, so a FiFo file type system in Visual Basic.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
how I can limit the size of the file
By file size, or number of lines?
atomicgs12Author Commented:
kaufmed: -
Your joking correct?

I'm looking for sample code.
Hope it might help

To Get File Size:

Imports System.IO

Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Your joking correct?

Hmmm...  I don't remember putting a winking emoticon or a "j/k" in my post...  maybe I'm getting senile.
1.) Checking the file size has been answered before.

2.) Deleting the first line of a file is not possible without writing the whole file again, because all content of the file would have to be shifted by xx bytes.
What you can do is reading the file with My.Computer.FileSystem.ReadAllText, cut off the first x lines (for example the first 10% or the half of the file) and write the changed file back with My.Computer.Filesystem.WriteAllText
A more common way is to do log rotation. You have 2 log files. If one is full, you delete the other file and write into a new one.
Another way I have used is simple reducing the amount of logged data. If the file is empty I log every event, if the file is full I log only critical errors.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.