I want those text files(log files) in a folder that is created today that has name as something20130416 and which has the word error only in the last 5 lines of it. Then attach these files and send to an email address. Am completely new to VB. I don't know how to put those files in an array or something and then attach them to mail. So far my code is:

Class Program
    Public Shared Sub Main(ByVal args As String())

        Dim log_files() As String = Directory.GetFiles("C\~", DateTime.Today.ToString("*yyyyMMdd") & ".log")

        For Each filesfound As String In log_files

            Dim contents = IO.File.ReadAllLines(filesfound)

            For counter As Integer = contents.Length - 1 To 5 Step -1

                If contents.Contains("error") Then   
                'Not sure what to do here
                    Email()
                End If

            Next

        Next
    End Sub

    Public Shared Sub Email()
        Dim m As New MailMessage()
        Dim attach = New Attachment("...")
        Dim sc As New SmtpClient()
        Try
            m.From = New MailAddress("example@gmail.com", "User")
            m.To.Add(New MailAddress("example@gmail.com", "User"))
            m.CC.Add(New MailAddress("example@gmail.com", "User"))
            m.Attachments.Add(attach)

            m.Subject = "Test1"
            m.IsBodyHtml = True
            m.Body = " These text files contains an error"
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub
 End Class

Sorry the code got posted twice. Its from class Program to end class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.