473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Log File

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


Nov 19 '05 #1
2 1203
> 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

Nov 19 '05 #2
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.

"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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.