cchristopher
asked on
Limit log file size
I have a VB.NET application that appends logs to a text file. I want to keep the size of the file to 3 megs, Is there a way to delete older lines and add new lines if the size is exceeded?
What you're going to have to do is read the file into memory, trim off the first x lines, and write it back such that you don't exceed the size you're looking for.
It is so much work for nothing and I dont think it is clever to delete logs, you should keep them for months or years.
But if space is a problem for you....you should keep 2 files of 3mb, your control will be more easy and you only need to do something like that:
1) Get log filename target ( file1 or file2 )
2) Verify if size > 3mb
2.1) Yes? delete if already exists the next logfile target
3) write your log
But if space is a problem for you....you should keep 2 files of 3mb, your control will be more easy and you only need to do something like that:
1) Get log filename target ( file1 or file2 )
2) Verify if size > 3mb
2.1) Yes? delete if already exists the next logfile target
3) write your log
ASKER
I am looking for a log file that will rotate if it exceeds the size. Does anyone have any other ideas?
.Net has built-in windows event log classes and event logs can have a specified size with an over-write as needed.
Just check the file you are writing to I'd the size is bigger than or equal to 3.
Sorry. It dosen't make sense to erase lines from a log file and write new lines.
You can flush the file. If space is a problem then zip them.
You can flush the file. If space is a problem then zip them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Did not answer the actual question. Work around was provided.