473,386 Members | 1,810 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,386 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 1292
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.