Log File

S

Smitha Patel

I am writing all my application activity to a log file(ASCII file).

1. How to append the data to a log file? I do not want to open the entire
file and add one line of log data to the file. My file will be in mega bytes
and it is a performance issue to load the entire file to memory and write
one line of data.

2. How to design the application in such a way that once the log file
reaches size of 'X', the log file will be written at the end of file and the
first entry is removed so that the log file will not grow beyond file size
of 'X'.. Any technique to achieve this?

VB.Net Desktop application and .Net Framework 1.1.

Thanks,

Patel
 
B

Brock Allen

1. How to append the data to a log file? I do not want to open the
entire file and add one line of log data to the file. My file will be
in mega bytes and it is a performance issue to load the entire file to
memory and write one line of data.
File.AppendText

2. How to design the application in such a way that once the log file
reaches size of 'X', the log file will be written at the end of file
and the first entry is removed so that the log file will not grow
beyond file size of 'X'.. Any technique to achieve this?

You'll have to build this one yourself. I don't know of any existing samples,
but you could always google.
 
U

UJ

What we usually do to keep the log files small - use today's date as the
name of the file. Before writing to it, check to make sure the file exists.
If it doesn't exist, count the number of files and if it's more than some
predefined number (say 10), delete the oldest one. The only reason for the
check if the file exists is in theory you will only be checking once a day
instead of every time you write to the file.

Another possibility would be to check how big the file is. If it's past a
certain point, rename the file to something like 'LogFile1.sav' and start a
new file.

As far as deleting the first message in the file when your appending at the
end, you would probably need to process the entire file (read 1 line and
ignore it, then read all the rest of the lines) which sounds like a lot of
overhead. I don't think you want to go this route.

If you were save to a SQL table, then it would be easy because you could
delete the oldest record. But that's doing it through SQL server not a text
file.

Hope this helps.

Jeffrey.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top