Challange for Experts (Monitoring Log files)

Posted on 2006-06-19
Last Modified: 2010-05-18
Dear VB Experts,

I need to build new applicatio using VB 6.0 to monitor a log file in a server, with frequintly repeated check every period og time, the program has to detect if there is any new jobs recorded in the log file or any updates on an already existing job in this log.
Now if there is new job, a new record must be inserted in a table in SQLserver DB with incompleted status, and recheck again for new and updates. if there is new jobs then insert again else check for the aleardy inserted jobs and not completed if there is any updates or modifications to update the status.
So, My procedure is a monitoring for a log file in a fax server, each fax job has more than one record one when just entered the accepted and the ready to be sent finally its successfully sent or not. so i need to check, insert if new or update if existing and check again.

Please advice ASAP

Thnx in advance
Question by:obmtech
LVL 14

Expert Comment

ID: 16936177
There's not really enough information here to help you, as this project depends entirely on the structure of the log file you want to monitor (and to a lesser extent, on the database you want to push information to).

Expert Comment

ID: 16937548
3 ways to detect changes:

1. Check the last modified date of the file
2. record the file size
3. take an md5 hash of the file

Author Comment

ID: 16940726
Here is one succesfull job from my log file:

|100|2006/05/29 08:42:00|Received job from user "USER_NAME" (Job assigned ID 275018).|FAX|WEBSERVER|3|28553||fpFax.cpp|708|2524|2852|
|100|2006/05/29 08:42:00|Job 275018 placed in fax queue for processing. |FAX|WEBSERVER|0|0||fpFax.cpp|710|2524|2852|
|100|2006/05/29 08:42:33|Prefetch thread processing requests|FAX|WEBSERVER|0|0||FetchThread.cpp|51|2524|3072|
|100|2006/05/29 08:42:33|Fetching data objects for job 275018|FAX|WEBSERVER|0|0||FetchThread.cpp|145|2524|3072|
|100|2006/05/29 08:42:33|Prefetch Normal Document success for job 275018|FAX|WEBSERVER|0|0||FetchThread.cpp|162|2524|3072|
|100|2006/05/29 08:42:33|Data found and ready to be exported for job 275018|FAX|WEBSERVER|0|0||FetchThread.cpp|212|2524|3072|
|100|2006/05/29 08:43:26|OCR Page Licenses as of 5/29/2006 8:43:26 AM: 24201|OCR|WEBSERVER|3|0||OCRDongleThread.cpp|104|2524|3052|
|100|2006/05/29 08:43:30|Found a faxable job|FAX|WEBSERVER|0|0||FaxThread.cpp|215|2524|3068|
|100|2006/05/29 08:43:30|Fax thread processing requests|FAX|WEBSERVER|0|0||FaxThread.cpp|71|2524|3068|
|100|2006/05/29 08:43:30|Fax job 275018 found and ready to be fax. Retries remaining 2.|FAX|WEBSERVER|3|28556||FaxThread.cpp|130|2524|3068|
|100|2006/05/29 08:43:30|Job 275018 being posted to gamma queue for phone number "FAX_Number".|FAX|WEBSERVER|0|0||FaxThread.cpp|132|3068|
|100|2006/05/29 08:43:30|Job submitted to fax H/W|FAX|WEBSERVER|0|0||FaxThread.cpp|143|2524|3068|
|100|2006/05/29 09:08:31|Fax job 275018 successfully sent to CEO office. Fax Server: A|FAX|WEBSERVER|3|28503|USER_NAME|FaxBaseThread.cpp|66|2524|3084|
|100|2006/05/29 09:08:31|Fax job 275018 successfully sent to all users. Fax Server: A|FAX|WEBSERVER|3|28504|USER_NAME|FaxBaseThread.cpp|66|2524|3084|

WEBSERVER is the server name

I hope it will help
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 10

Assisted Solution

cool12399 earned 250 total points
ID: 16944797

(a) Assuming that log file is a text file (i.e., "log.txt").
(b) I'm assuming you have the necessary read/write permissions/etc to your log file, etc, etc, and
that is not a huge log file (otherwise you'd simply use the 'seek' command in VB to go to the end of
the file and read the last line. A little extra coding, not a big deal).


1. Create a VB app.
2. Add a 'timer' control.
3. Set your interval for how 'often' you want to check the log (i.e. every second? every minute? every 5 minutes?).
The 'interval' is in milliseconds, so 1 second = 1000.
4. In your timer code, simply do your read/write code to determine whether a new job has been added. Assuming
you are having this code running on your system, and staying open, one very easy way is simply to:
i) read through the entire text file (i.e., while not eof(1) ... read file ... wend), and stick the last line in
a global variable, say called 'lastLineRead'. Then, when you read the file this time, see if the last line read
is equal to the one you set in your global variable. If it is, then you don't need to do anything. Otherwise, you
do whatever it is you wanted to do with the new information.

And voila! You now know how to monitor your log files through vb6 code.
LVL 10

Expert Comment

ID: 16944805
oh, and yes, re: the SQL etc, of course, you would add the necessary SQL code (i.e., insert/update/etc whatever).

Accepted Solution

justchat_1 earned 250 total points
ID: 16945410
Even simpler and less resource intensive...

use LOF(filename) to store the size of the file


GetAttr(PathName As String) to get the last modified date

...personally the first one is the easiest

Expert Comment

ID: 17293840
Correct answer given by me and cool12399, awaiting points...

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question