Hi there
ive managed to muddle through and write a small program that reads a particular log file, checks for the word "error" and then sends an email notification. At the moment the program sends an email even if there are no new errors & i dont want it to send blank emails. Could some1 pls tell me where ive gone wrong? here is my code:
Imports System
Imports System.IO
Imports System.Collections
Imports System.Web
Module Module1
Sub Main()
Dim myTimer As New System.Timers.Timer
Dim LineNo As String
myTimer.Stop()
Dim CurrentLineNo As New Integer
If GetSetting("OrEM", "Settings", "LineNo"
= "" Then
SaveSetting("OrEM", "Settings", "LineNo", "1"
End If
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
)
Dim objReader As New StreamReader("filename"
Dim sLine As String = ""
Dim arrText As New ArrayList
Do
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If CurrentLineNo >= LineNo Then
If InStr(UCase(sLine), "MON"
Or InStr(UCase(sLine), "TUE"
Or InStr(UCase(sLine), "WED"
Or InStr(UCase(sLine), "THU"
Or InStr(UCase(sLine), "FRI"
Or InStr(UCase(sLine), "SAT"
Or InStr(UCase(sLine), "SAT"
Then
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If InStr(UCase(sLine), "ERROR"
Then arrText.Add(sLine)
While sLine <> ""
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
End While
End If
End If
If Not sLine Is Nothing Then
End If
Loop Until sLine Is Nothing
objReader.Close()
If sLine <> "" Then
'create mail notification
Dim mailMsg As New System.Web.Mail.MailMessage
mailMsg.BodyFormat = Mail.MailFormat.Text
mailMsg.To = "me@co.uk"
mailMsg.Subject = "name"
mailMsg.From = "name"
Dim txtBody As String
For Each sLine In arrText
txtBody = txtBody & sLine & vbCrLf
Next
mailMsg.Body = txtBody
System.Web.Mail.SmtpMail.SmtpServer = "server"
System.Web.Mail.SmtpMail.Send(mailMsg)
End If
SaveSetting("OrEm", "Settings", "LineNo", Trim(Str(CurrentLineNo - 2)))
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
)
CurrentLineNo = 0
myTimer.Interval = 30000
myTimer.Start()
End Sub
End Module
It hasn't worked since i added the (if sline <> "" then.......end if) which is wrapped around the mail code?
Thanx - any help much appreciated!
Imports System
Imports System.IO
Imports System.Collections
Imports System.Web
Module Module1
Sub Main()
Dim myTimer As New System.Timers.Timer
Dim LineNo As String
myTimer.Stop()
Dim CurrentLineNo As New Integer
If GetSetting("OrEM", "Settings", "LineNo"
SaveSetting("OrEM", "Settings", "LineNo", "1"
End If
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
Dim objReader As New StreamReader("filename"
Dim sLine As String = ""
Dim arrText As New ArrayList
Do
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If CurrentLineNo >= LineNo Then
If InStr(UCase(sLine), "MON"
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
If InStr(UCase(sLine), "ERROR"
While sLine <> ""
sLine = objReader.ReadLine() : CurrentLineNo = CurrentLineNo + 1
End While
End If
End If
If Not sLine Is Nothing Then
End If
Loop Until sLine Is Nothing
objReader.Close()
If sLine <> "" Then
'create mail notification
Dim mailMsg As New System.Web.Mail.MailMessage
mailMsg.BodyFormat = Mail.MailFormat.Text
mailMsg.To = "me@co.uk"
mailMsg.Subject = "name"
mailMsg.From = "name"
Dim txtBody As String
For Each sLine In arrText
txtBody = txtBody & sLine & vbCrLf
Next
mailMsg.Body = txtBody
System.Web.Mail.SmtpMail.SmtpServer = "server"
System.Web.Mail.SmtpMail.Send(mailMsg)
End If
SaveSetting("OrEm", "Settings", "LineNo", Trim(Str(CurrentLineNo - 2)))
LineNo = Val(GetSetting("OrEM", "Settings", "LineNo"
CurrentLineNo = 0
myTimer.Interval = 30000
myTimer.Start()
End Sub
End Module
It hasn't worked since i added the (if sline <> "" then.......end if) which is wrapped around the mail code?
Thanx - any help much appreciated!