Wednesday, October 9, 2013

Log File in VB.Net

Saved Log File

Imports System.IO.StreamWriter

Private Sub log_file()
        Try
            Dim s As IO.StreamWriter
            Dim portfolioPath As String = My.Application.Info.DirectoryPath
            If Not IO.Directory.Exists("C:\Users\Arka\Desktop\Arka_emp") Then
                IO.Directory.CreateDirectory("C:\Users\Arka\Desktop\Arka_emp")
                IO.File.Create("C:\Program Files\log.txt").Close()
                s = New IO.StreamWriter("C:\Program Files\log.txt", True)
                s.WriteLine(Date.Now & " Insert ERROR in Name " & dt.Rows(x)(1))
                s.Flush()
                s.Close()
            Else
                s = New IO.StreamWriter("C:\Program Files\log.txt", True)
                s.WriteLine(Date.Now & " Insert ERROR in Name " & dt.Rows(x)(1))
                s.Flush()
                s.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

Runtime Log File

Private Sub log_file()

        System.Diagnostics.Process.Start("notepad")
        Dim found As Boolean = False
        Do Until found = True
            System.Threading.Thread.Sleep(100)
            For Each p As Process In Process.GetProcesses
                If p.ProcessName = "notepad" Then
                    found = True
                End If
            Next
        Loop
        SendKeys.Send("Whatever you want to say..." & Environment.NewLine & "And you can make new lines too!")
    End Sub

No comments:

Post a Comment