jj: check for logfile, log directory on creation
This commit is contained in:
parent
0ccdb7bbc7
commit
4e08cd757d
@ -100,12 +100,36 @@ Public Class Logger
|
||||
Dim appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||
basePath = Path.Combine(appDataDir, companyName, productName)
|
||||
ElseIf logPath = PathType.CurrentDirectory Then
|
||||
Dim currentDirectory As String = Environment.CurrentDirectory
|
||||
Dim currentDirectory As String = My.Application.Info.DirectoryPath
|
||||
|
||||
basePath = Path.Combine(currentDirectory, "Log")
|
||||
Else 'Custom Path
|
||||
basePath = customLogPath
|
||||
End If
|
||||
|
||||
' If directory does not exist, try to create it!
|
||||
If Not Directory.Exists(basePath) Then
|
||||
Try
|
||||
Directory.CreateDirectory(basePath)
|
||||
Catch ex As Exception
|
||||
' If creation fails, use failSafe path
|
||||
basePath = failSafePath
|
||||
End Try
|
||||
End If
|
||||
|
||||
' Try to create a file in `basePath` to check write permissions
|
||||
Try
|
||||
Dim fileAccessPath = Path.Combine(basePath, "accessTest.txt")
|
||||
Using fs As FileStream = File.Create(fileAccessPath)
|
||||
fs.WriteByte(0)
|
||||
End Using
|
||||
|
||||
File.Delete(fileAccessPath)
|
||||
Catch ex As UnauthorizedAccessException
|
||||
' If creation fails, use failSafe path
|
||||
basePath = failSafePath
|
||||
End Try
|
||||
|
||||
' Create config object and initalize it
|
||||
config = New LoggingConfiguration()
|
||||
config.Variables("product") = productName
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user