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.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:78**********************@msnews.microsoft.com ...
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.
-Brock
DevelopMentor
http://staff.develop.com/ballen