diff --git a/Modules.Logging/Constants.vb b/Modules.Logging/Constants.vb
deleted file mode 100644
index ea428f0e..00000000
--- a/Modules.Logging/Constants.vb
+++ /dev/null
@@ -1,8 +0,0 @@
-'''
-''' Keeps the constants needed for the Logger
-'''
-Public Class Constants
- Public Const KEEP_FILES_OPEN As Boolean = False
- Public Const MAX_ARCHIVE_FILES_DEFAULT As Integer = 30
- Public Const MAX_ARCHIVE_FILES_DEBUG_DETAIL As Integer = 1
-End Class
diff --git a/Modules.Logging/Logger.vb b/Modules.Logging/Logger.vb
index 44a903e2..f0b2a496 100644
--- a/Modules.Logging/Logger.vb
+++ b/Modules.Logging/Logger.vb
@@ -1,5 +1,4 @@
Imports System.IO
-
Imports NLog
Imports NLog.Config
Imports NLog.Targets
@@ -19,8 +18,7 @@ Imports NLog.Targets
'''
''' DEPENDENCIES: NLog, >= 4.5.8
'''
-''' PARAMETERS: product, String
-''' logPath, PathType
+''' PARAMETERS: logPath, PathType
''' customLogPath, String (optional)
'''
''' PROPERTIES: LogFile, String (readonly)
@@ -28,6 +26,11 @@ Imports NLog.Targets
''' Debug, Boolean
'''
Public Class Logger
+ Private Const KEEP_FILES_OPEN As Boolean = False
+ Private Const MAX_ARCHIVE_FILES_DEFAULT As Integer = 30
+ Private Const MAX_ARCHIVE_FILES_DEBUG_DETAIL As Integer = 1
+ Private Const ARCHIVE_EVERY As FileArchivePeriod = FileArchivePeriod.Minute
+
Private Const FILE_NAME_FORMAT_DEFAULT As String = "${shortdate}-${var:product}.log"
Private Const FILE_NAME_FORMAT_DETAIL As String = "${shortdate}-${var:product}-Detail.log"
Private Const FILE_NAME_FORMAT_DEBUG As String = "${shortdate}-${var:product}-Debug.log"
@@ -86,13 +89,15 @@ Public Class Logger
''' - CurrentDirectory: writes to `Log` directory relative to the current directory
''' - CustomPath: writes to custom path specified in `customLogPath`
'''
- ''' An name that identifies the Logs
''' The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.
''' If `logPath` is set to custom, this defines the custom logPath
- Public Sub New(product As String, logPath As PathType, Optional customLogPath As String = Nothing)
+ Public Sub New(logPath As PathType, Optional customLogPath As String = Nothing)
+ Dim productName As String = My.Application.Info.ProductName
+ Dim companyName As String = My.Application.Info.CompanyName
+
If logPath = PathType.AppData Then
Dim appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
- basePath = Path.Combine(appDataDir, "Digital Data", product)
+ basePath = Path.Combine(appDataDir, companyName, productName)
ElseIf logPath = PathType.CurrentDirectory Then
Dim currentDirectory As String = Environment.CurrentDirectory
basePath = Path.Combine(currentDirectory, "Log")
@@ -100,20 +105,28 @@ Public Class Logger
basePath = customLogPath
End If
+ ' Create config object and initalize it
config = New LoggingConfiguration()
- config.Variables("product") = product
+ config.Variables("product") = productName
+ ' Add default targets
config.AddTarget(TARGET_DEFAULT_EX, GetDefaultLogTargetWithExceptions(basePath))
config.AddTarget(TARGET_DEFAULT, GetDefaultLogTarget(basePath))
config.AddTarget(TARGET_DETAIL, GetDetailLogTarget(basePath))
config.AddTarget(TARGET_DEBUG, GetDebugLogTarget(basePath))
+ ' Add default rules
+ config.AddRuleForOneLevel(LogLevel.Error, TARGET_DEFAULT_EX)
+ config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_DEFAULT_EX)
+ config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
+ config.AddRuleForOneLevel(LogLevel.Info, TARGET_DETAIL)
+
+ ' Save config
+ LogManager.Configuration = config
+
+ ' Save log paths for files/directory
LogDirectory = basePath
LogFile = GetCurrentLogFilePath()
-
- AddDefaultLogTargets()
-
- LogManager.Configuration = config
End Sub
'''
@@ -137,7 +150,10 @@ Public Class Logger
config.LoggingRules.Clear()
' Add default targets and debug target
- AddDefaultLogTargets()
+ config.AddRuleForOneLevel(LogLevel.Error, TARGET_DEFAULT_EX)
+ config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_DEFAULT_EX)
+ config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
+ config.AddRuleForOneLevel(LogLevel.Info, TARGET_DETAIL)
If Debug Then
config.AddRuleForOneLevel(LogLevel.Debug, TARGET_DEBUG)
@@ -147,63 +163,52 @@ Public Class Logger
LogManager.ReconfigExistingLoggers()
End Sub
- '''
- ''' Adds default rules
- '''
- Private Sub AddDefaultLogTargets()
- config.AddRuleForOneLevel(LogLevel.Error, TARGET_DEFAULT_EX)
- config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_DEFAULT_EX)
- config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
- config.AddRuleForOneLevel(LogLevel.Info, TARGET_DETAIL)
- End Sub
#Region "Log Targets"
Private Function GetDefaultLogTarget(basePath As String) As FileTarget
- Dim defaultFilePath As String = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT)
Dim defaultLog As New FileTarget() With {
+ .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT),
.Name = TARGET_DEFAULT,
- .FileName = defaultFilePath,
.Layout = LOG_FORMAT_DEFAULT,
- .MaxArchiveFiles = 30,
- .KeepFileOpen = Constants.KEEP_FILES_OPEN
+ .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEFAULT,
+ .ArchiveEvery = ARCHIVE_EVERY,
+ .KeepFileOpen = KEEP_FILES_OPEN
}
-
-
Return defaultLog
End Function
Private Function GetDefaultLogTargetWithExceptions(basePath As String) As FileTarget
- Dim defaultFilePath As String = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT)
Dim defaultLogWithExceptionData As New FileTarget() With {
+ .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEFAULT),
.Name = TARGET_DEFAULT_EX,
- .FileName = defaultFilePath,
.Layout = LOG_FORMAT_EXCEPTION,
- .MaxArchiveFiles = 30,
- .KeepFileOpen = Constants.KEEP_FILES_OPEN
+ .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEFAULT,
+ .ArchiveEvery = ARCHIVE_EVERY,
+ .KeepFileOpen = KEEP_FILES_OPEN
}
Return defaultLogWithExceptionData
End Function
Private Function GetDetailLogTarget(basePath As String) As FileTarget
- Dim detailFilePath As String = Path.Combine(basePath, FILE_NAME_FORMAT_DETAIL)
Dim detailLog As New FileTarget() With {
+ .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DETAIL),
.Name = TARGET_DETAIL,
- .FileName = detailFilePath,
.Layout = LOG_FORMAT_DEFAULT,
- .MaxArchiveFiles = 1,
- .KeepFileOpen = Constants.KEEP_FILES_OPEN
+ .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL,
+ .ArchiveEvery = ARCHIVE_EVERY,
+ .KeepFileOpen = KEEP_FILES_OPEN
}
Return detailLog
End Function
Private Function GetDebugLogTarget(basePath As String) As FileTarget
- Dim debugFilePath As String = Path.Combine(basePath, FILE_NAME_FORMAT_DEBUG)
Dim debugLog As New FileTarget() With {
+ .FileName = Path.Combine(basePath, FILE_NAME_FORMAT_DEBUG),
.Name = TARGET_DEBUG,
- .FileName = debugFilePath,
.Layout = LOG_FORMAT_DEFAULT,
- .MaxArchiveFiles = 1,
- .KeepFileOpen = Constants.KEEP_FILES_OPEN
+ .MaxArchiveFiles = MAX_ARCHIVE_FILES_DEBUG_DETAIL,
+ .ArchiveEvery = ARCHIVE_EVERY,
+ .KeepFileOpen = KEEP_FILES_OPEN
}
Return debugLog
diff --git a/Modules.Logging/Modules.Logging.vbproj b/Modules.Logging/Modules.Logging.vbproj
index 3d375bac..75695712 100644
--- a/Modules.Logging/Modules.Logging.vbproj
+++ b/Modules.Logging/Modules.Logging.vbproj
@@ -72,7 +72,6 @@
-
diff --git a/Modules.Logging/My Project/AssemblyInfo.vb b/Modules.Logging/My Project/AssemblyInfo.vb
index ee079d9d..86c3cb7f 100644
--- a/Modules.Logging/My Project/AssemblyInfo.vb
+++ b/Modules.Logging/My Project/AssemblyInfo.vb
@@ -10,7 +10,7 @@ Imports System.Runtime.InteropServices
-
+
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
'
-
+