A log utility : Log « Development « VB.Net Tutorial






Imports System
Imports System.IO

public class LogTest
   public Shared Sub Main
        MyLog.Log("Started Up", "C:\test.txt")
        MyLog.Log(String.Format("DisplayName called, {0} {1} output","B", "A"), "C:\test.txt")
   End Sub
End class

Public Class MyLog
    Const DefaultLogFile As String = "C:\LogFile.txt"

    Shared Sub Log(ByVal Message As String,ByVal FileName As String)
        Dim objLogFile As StreamWriter
        
        If IO.File.Exists(FileName) Then
            objLogFile = File.AppendText(FileName)
        ElseIf Directory.Exists (Path.GetDirectoryName(FileName)) Then
            objLogFile = File.CreateText(FileName)
        Else
            objLogFile = File.AppendText(DefaultLogFile)
        End If

        objLogFile.WriteLine(Message)
        objLogFile.Flush()
        objLogFile.Close()
    End Sub
End Class








7.14.Log
7.14.1.My.Application.Log.DefaultFileLogWriter.FullLogFileName
7.14.2.A log utility