Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read log file, if archive stopped for 2 hours or more, send alert

Status
Not open for further replies.

honeypot

Technical User
Mar 6, 2001
147
GB
Hi :) ive managed to write a console app that reads a log file checks for the word "error" then sends email notification if true. The program reads the file every 5 mins. Next i have to check for "archival stopped" & if it is still in this state for 2 hours or more send an email notification. Can sum1 pls help as i'm a newbie? :)
ive also realised that maybe i shd have written the program as a windows app as the console app runs through, does its stuff and then closes - is there a way around this? Thanx.
 
There's no reason why the console application should have to close after it does its thing. You can have your [tt]Main()[/tt] function continuously loop, calling functions to do whatever checks need to be done periodically.

As for sending an email after two hours in a certain state, you can use a DateTime variable that indicates the time at which you started being in the state you're concerned about.

for example:
Code:
If ([COLOR=blue]in appropriate state[/color]) Then
    If (Not stateStart Is Nothing) Then
        stateStart = DateTime.Now
    ElseIf (DateTime.Now.Subtract(stateStart).TotalHours > 2.0) Then
        [COLOR=blue]send the email -- make sure to have a flag to make sure it's not continually sent[/color]
    End If
Else
    ' Not in the state, so set to Nothing.  This will ensure that our counter starts fresh next time.
    stateStart = Nothing
End If

Something along those lines, anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top