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
                End If


    End Sub

    Public Shared Sub Email()
        Dim m As New MailMessage()
        Dim attach = New Attachment("...")
        Dim sc As New SmtpClient()
            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.Subject = "Test1"
            m.IsBodyHtml = True
            m.Body = " These text files contains an error"
        Catch e As Exception
        End Try
    End Sub
 End Class

Edited 3 Years Ago by rohit69: code got posted twice

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

This article has been dead for over six months. Start a new discussion instead.