473,378 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 1290
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: CHANGE username to westes | last post by:
What are the most popular, and well supported, libraries of drivers for bar code scanners that include a Visual Basic and C/C++ API? My requirements are: - Must allow an application to be...
8
by: Claudio Grondi | last post by:
It is maybe not a pure Python question, but I think it is the right newsgroup to ask for help, anyway. After connecting a drive to the system (via USB or IDE) I would like to be able to see...
79
by: pinkfloydhomer | last post by:
I want to scan a file byte for byte for occurences of the the four byte pattern 0x00000100. I've tried with this: # start import sys numChars = 0 startCode = 0 count = 0
4
by: Zen | last post by:
I'm using Access 2000, and I'd like to know if there is a way to use a scanner (flatbed, doc-feed, etc) to scan forms with OMR or OCR software, and have the data be automatically (or if not...
0
by: Brent Burkart | last post by:
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...
10
by: Alan Searle | last post by:
I would like to scan a directory structure into XML to offer navigation functionality in HTML / XSL pages. My questions are: 1. Which is the best structure to store variable depth heirarchies...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
4
by: tshad | last post by:
We have a few pages that accept uploads and want to scan the files before accepting them. Does Asp.net have a way of doing a virus scan? We are using Trendmicro to scan files and email but don't...
23
by: Rotsey | last post by:
Hi, I am writing an app that scans hard drives and logs info about every fine on the drive. The first iteration of my code used a class and a generic list to store the data and rhis took...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.