Solved

Delete line from text file

Posted on 2006-07-08
4
226 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
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 29

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now