(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
A log utility
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
My.Application.Log.DefaultFileLogWriter.FullLogFileName
Option Strict On
Public Module ApplicationLog
Public Sub Main()
Dim logFile As String = My.Application.Log.DefaultFileLogWriter.FullLogFileName
Console.WriteLine("Location of Application Log File: {0} {1}", vbCrLf, logFile)
End Sub
End Module
Location of Application Log File:
C:\Documents and Settings\Joe\Application Data\ApplicationLog\ApplicationLog\0.0.0.0\main.log