473,651 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3649
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.goog legroups.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.goog legroups.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
1193
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 PostedFile object. But for some reason this will not work for a file. Below is the code that I tried: // provide read access to the file
3
1971
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 return it from the server and it looks good, well formed and all. But, when I use Explorer to hit the .aspx page, it returns the document but sticks this in the document some place: <SN>96620150</SN> << The XML page cannot be displayed Cannot view...
1
5403
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 web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but I can;t convert the image. I certainly don't want to upload it the the server filesystem, convert...
6
20244
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 not support automatic wsdl generation of custom headers so the wsdl has no information regarding the required header. I've read through a lot of material and managed to get a workable solution but it is far from ideal. I created a new...
2
2279
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 that will get put in the datagridview. The column is bound to a sql server 2005 image data field. I just need to know how to put the image in the column. Any help appreciated. Bob
3
2974
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 an exceptions is thrown somewhere in between the process. My current approach: 1. read current contents of the file
1
1613
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 next batch of controls.. Is that possible..? Currently it is just appending to the current line and wrapping around when it reaches the end of the display area. E.g. The panel populates a list of questions and radio buttons for the
2
3075
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 section: Discography --------------------- DiscID
2
3584
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 vertices in that graph to each other. I can see that my hard-drive is working very hard throughout the operation. The operation took about 2 hours (I just canceled it at this point, looked like it was about 10% done) with 200,000 vertices and an...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8695
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.