Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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
   }
}

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • 2 weeks later...
Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...