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 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
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
"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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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...
|
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...
|
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
| |
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
|
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
|
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
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |