laxman Posted September 16, 2008 Posted September 16, 2008 hai all i am developing a windows application, in this application i am creating log file(textfile), here i want to generate the report based on the log file i am able to read full data but i want to capture the line which contains specifik key word here i am unable get the line which contains the specific key word let me know how to do this thanks in advance Quote
Administrators PlausiblyDamp Posted September 16, 2008 Administrators Posted September 16, 2008 You would have to read through the file a line at a time and check each line for the keyword in question. Alternatively you could read the entire file into memory and split it into an array of strings then loop over the array looking for the keyword. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted September 16, 2008 Posted September 16, 2008 String[] lines = System.IO.File.ReadAllLines("YourFilePath.log"); foreach (String line in lines) { if (line.Contains(yourKeyWord) == true) { //do work } } This could also be done without the extra variable, but the above helps illustrate what is happening. foreach (String line in System.IO.File.ReadAllLines("YourFilePath.log")) { if (line.Contains(yourKeyWord) == true) { //do work } } Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
laxman Posted September 26, 2008 Author Posted September 26, 2008 thank you for your reply and i am able to get the data by using contains key word.here my problem is i am updating each and every time if user does any thing so if suddenly power off shut down, after restarting i have to get the last six lines or last say some half an hour data in the file if any one suggest with one example it would be great thank you Quote
Administrators PlausiblyDamp Posted September 26, 2008 Administrators Posted September 26, 2008 You could open the file using a filestream and seek to a couple of k from the end, then open a streamreader on top of the filestream and read from there. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.