Solved

Delete line from text file

Posted on 2006-07-08
4
230 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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