473,320 Members | 1,951 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,320 software developers and data experts.

Inserting into a stream

I have been tasked with writing code which overrides the TraceListener
class for the purpose of limiting the size of the log file. Basically,
when the log file grows to a certain size, I need to begin overwriting
it from the beginning. I am using a ReadWrite Stream to do this. My
problem is the fact that the lines which are to overwrite the old ones
are not necessarily going to be the same size. For instance, if the
first line in the log file was 20 bytes and then a new line character,
the line to overwrite it might be 26 characters before its new line.
How can I insert this without overwriting part of the next line in the
stream. Is there any way to "insert" into the stream?

thanks,

Z

Oct 16 '06 #1
4 3587
Zenon,
There are a number of ways to approach this, including the use of "Rollover"
log files where the original file is given a new name and a new current log
file is started.

But if you only want to do what you state in your post, all you probably
need to do is first check the size of the file. If it is not over the limit
you would open the file for writing with FileMode.Append, otherwise you would
use FileMode.Create and this would automatically overwrite the old file,
starting with a brand new file of the same name.

Keep it simple.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Zenon" wrote:
I have been tasked with writing code which overrides the TraceListener
class for the purpose of limiting the size of the log file. Basically,
when the log file grows to a certain size, I need to begin overwriting
it from the beginning. I am using a ReadWrite Stream to do this. My
problem is the fact that the lines which are to overwrite the old ones
are not necessarily going to be the same size. For instance, if the
first line in the log file was 20 bytes and then a new line character,
the line to overwrite it might be 26 characters before its new line.
How can I insert this without overwriting part of the next line in the
stream. Is there any way to "insert" into the stream?

thanks,

Z

Oct 16 '06 #2
Sorry, I probably didn't explain this well. I am actually supposed to
implement 2 different rollover methods. The one you described about
starting a new file when the max size is reached is already done, that
was the easy one. The second method I attempted to describe only
creates one file. When that file reaches a certain size, it begins
overwriting itself, one line at a time so that the maximum amount of
history is retained. For instance, if the max file size is reached
after 10 lines are written, the 11th would overwrite the first but 2
throuth 10 would remain intact.

Peter Bromberg [ C# MVP ] wrote:
Zenon,
There are a number of ways to approach this, including the use of "Rollover"
log files where the original file is given a new name and a new current log
file is started.

But if you only want to do what you state in your post, all you probably
need to do is first check the size of the file. If it is not over the limit
you would open the file for writing with FileMode.Append, otherwise you would
use FileMode.Create and this would automatically overwrite the old file,
starting with a brand new file of the same name.

Keep it simple.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Zenon" wrote:
I have been tasked with writing code which overrides the TraceListener
class for the purpose of limiting the size of the log file. Basically,
when the log file grows to a certain size, I need to begin overwriting
it from the beginning. I am using a ReadWrite Stream to do this. My
problem is the fact that the lines which are to overwrite the old ones
are not necessarily going to be the same size. For instance, if the
first line in the log file was 20 bytes and then a new line character,
the line to overwrite it might be 26 characters before its new line.
How can I insert this without overwriting part of the next line in the
stream. Is there any way to "insert" into the stream?

thanks,

Z
Oct 16 '06 #3
"Zenon" <ze****@comcast.netwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Sorry, I probably didn't explain this well. I am actually supposed to
implement 2 different rollover methods. The one you described about
starting a new file when the max size is reached is already done, that
was the easy one. The second method I attempted to describe only
creates one file. When that file reaches a certain size, it begins
overwriting itself, one line at a time so that the maximum amount of
history is retained. For instance, if the max file size is reached
after 10 lines are written, the 11th would overwrite the first but 2
throuth 10 would remain intact.
This second scenario is not realistic - it requires that you re-write all of
the file contents from the "insertion point" to the end every time you write
a message.

The only practical way to achieve something like that is to use a log file
with fixed-length records - which pretty much rules out text files.

-cd
Oct 16 '06 #4
Fair enough, thanks.

Carl Daniel [VC++ MVP] wrote:
"Zenon" <ze****@comcast.netwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Sorry, I probably didn't explain this well. I am actually supposed to
implement 2 different rollover methods. The one you described about
starting a new file when the max size is reached is already done, that
was the easy one. The second method I attempted to describe only
creates one file. When that file reaches a certain size, it begins
overwriting itself, one line at a time so that the maximum amount of
history is retained. For instance, if the max file size is reached
after 10 lines are written, the 11th would overwrite the first but 2
throuth 10 would remain intact.

This second scenario is not realistic - it requires that you re-write all of
the file contents from the "insertion point" to the end every time you write
a message.

The only practical way to achieve something like that is to use a log file
with fixed-length records - which pretty much rules out text files.

-cd
Oct 16 '06 #5

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

Similar topics

0
by: John Giblin | last post by:
Everytime I try to inset a blob from a file I get the following error. ORA-12571: TNS:packet writer failure. I was able to successful insert a blob from a post to another another page using the...
3
by: Steve | last post by:
Hello, I'm creating an .aspx page that gets an XML document (as a string) from a server via .NET remoting and returns it in the Response.Write method. I'm saving the document to a file before I...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
6
by: john deviney | last post by:
I have a C#/.Net 1.1 client talking to a Java based web service. I need to insert a soap header on the client side which is expected on the server side. Currently, the Java ws provider, Axis, does...
2
by: Bob | last post by:
I looked at the sample in the msdn january 2005 - Introducing a new datagrid, but the project downloaded failed to open. Any one can point me to a bit of code on how to go and select an image...
3
by: japi | last post by:
Hi, i would like to know what approach i should use to insert (not append) a line of text to the begin of an existing text file. My current approach works, but i am afraid of loosing data if...
1
by: Emma Middlebrook | last post by:
Hi, I've implemented an AJAX update panel on one of my ASP.NET web pages. I generate and add controls to it dynamically. What I would like to do is tell it to start a new line before adding the...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: aeblank | last post by:
THE PROBLEM I'm running into performance issues generating and storing a randomly created graph in a SQL Server database. I have a T-SQL script that generates a graph, and then randomly connects the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

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.