Clicky

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?

asked 06/10/2011 03:23

cchristopher's gravatar image

cchristopher ♦♦


8 Answers:
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.
link

answered

wellhole's gravatar image

wellhole

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
link

answered 2011-06-10 at 11:31:54

mrxrsd's gravatar image

mrxrsd

I am looking for a log file that will rotate if it exceeds the size. Does anyone have any other ideas?
link

answered 2011-06-10 at 12:50:49

cchristopher's gravatar image

cchristopher

.Net has built-in windows event log classes and event logs can have a specified size with an over-write as needed.
link

answered 2011-06-10 at 13:34:46

mastoo's gravatar image

mastoo

Just check the file you are writing to I'd the size is bigger than or equal to 3.

link

answered 2011-06-10 at 14:14:10

databoks's gravatar image

databoks

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.
link

answered 2011-06-10 at 18:13:08

databoks's gravatar image

databoks

Did not answer the actual question. Work around was provided.
link

answered 2011-06-12 at 07:38:19

cchristopher's gravatar image

cchristopher

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×8
×79

Asked: 06/10/2011 03:23

Seen: 332 times

Last updated: 12/16/2011 06:00