471,887 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Scanning content in a log file

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
Nov 20 '05 #1
3 1214
In article <#u**************@TK2MSFTNGP12.phx.gbl>,
Br***********@wvmb.com says...
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?

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
* "Brent Burkart" <Br***********@wvmb.com> scripsit:
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()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
In article <ey**************@TK2MSFTNGP10.phx.gbl>,
Br***********@wvmb.com says...
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.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by CHANGE username to westes | last post: by
79 posts views Thread by pinkfloydhomer | last post: by
reply views Thread by Brent Burkart | last post: by
10 posts views Thread by Alan Searle | last post: by
4 posts views Thread by tshad | last post: by
23 posts views Thread by Rotsey | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.