Scanning content in a log file

  • Thread starter Thread starter Brent Burkart
  • Start date Start date
B

Brent Burkart

I am using a streamreader to read a log file into my application. Now I
want to be able to scan for error messages, such as "failed", "error",
"permission denied", so I can take action such as send an email.

I am not quite sure how to approach this as far as scanning the content.

I currently read all of the contents in using the following

Dim contents As String = objStreamReader.ReadToEnd()

Then display it in a label.

Has anyone done this or can you point me in a direction.

Thanks,
Brent
 
I am using a streamreader to read a log file into my application. Now I
want to be able to scan for error messages, such as "failed", "error",
"permission denied", so I can take action such as send an email.

I am not quite sure how to approach this as far as scanning the content.

I currently read all of the contents in using the following

Dim contents As String = objStreamReader.ReadToEnd()

Then display it in a label.

Has anyone done this or can you point me in a direction.

How is the data in the log arranged? Is it a single-line per "log
entry"? Or can they span multiple lines?
 
Yeah, they will span multiple lines. Here is an example.

01/26/04 10:53:02 Importing file d:\Program
Files\x\x\PollDir\992FERGUSON,S.fnm.
01/26/04 10:53:09 Application '992FERGUSON,S ' already exists. This
application will not be imported.
01/26/04 10:53:09 Application '992FERGUSON,S ' failed to import.

Thanks for your help
 
* "Brent Burkart said:
I am using a streamreader to read a log file into my application. Now I
want to be able to scan for error messages, such as "failed", "error",
"permission denied", so I can take action such as send an email.

I am not quite sure how to approach this as far as scanning the content.

I currently read all of the contents in using the following

Dim contents As String = objStreamReader.ReadToEnd()

Then display it in a label.

Has anyone done this or can you point me in a direction.

You may want to read the file line-by-line:

\\\
Imports System.IO
..
..
..
Dim sr As New StreamReader("C:\WINDOWS\WIN.INI")
Dim strLine As String
strLine = sr.ReadLine()
Do Until strLine Is Nothing
MsgBox(strLine)
strLine = sr.ReadLine()
Loop
sr.Close()
///
 
Yeah, they will span multiple lines. Here is an example.

01/26/04 10:53:02 Importing file d:\Program
Files\x\x\PollDir\992FERGUSON,S.fnm.
01/26/04 10:53:09 Application '992FERGUSON,S ' already exists. This
application will not be imported.
01/26/04 10:53:09 Application '992FERGUSON,S ' failed to import.

You'll need something that can break the log out into manageable pieces.
Nothing in the sample you showed above indicates how you would know the
end of a multiline entry (for example, the last entry isn't even
multiline).

Do you have control of the log file format? If so, you might want to
include some delimiter line that indicates the end of a log entry (like
"*************************"). Then you could use Herfried's sample code
that reads a line at a time. Build up a string until you hit a
"*************************" line, and then can the entry using
String.SubString() to look for errors.
 
Back
Top