Solved

Delete line from text file

Posted on 2006-07-08
4
229 Views
Last Modified: 2010-04-16
I'd like a DeleteLine function to create some type of 'rolling log'
i.e., log file gets to a certain size, then starts deleteing lines from the top so that new lines can be added.

How can i do this?
0
Comment
Question by:gwarguitar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:MuhammadAdil
ID: 17067228
0
 

Author Comment

by:gwarguitar
ID: 17073475
umm... not seeing anything in there that helps me with my problem.
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 17078061
Primitive approach would be as follows:

read the file to a string variable and count number of lines (while loop...).
If number of lines exceeds some limit, take substring starting from the first occasion of newline character to the end (may be repeatedly), and save the result.
Quite costly operation however but easy to implement.
0
 
LVL 10

Accepted Solution

by:
Ready1 earned 50 total points
ID: 17276302
just a thought i use log4net to do all my logging in my application:

http://logging.apache.org/log4net/

it handles all the filesizes for you so you limit the size of your log file to eg. 100kb.. or it will auto rollover to a new file.

Regards,
Ready1
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question