|
|
|
|
@@ -3,88 +3,83 @@ Imports NLog
|
|
|
|
|
Imports NLog.Config
|
|
|
|
|
Imports NLog.Targets
|
|
|
|
|
|
|
|
|
|
''' <module>LogConfig</module>
|
|
|
|
|
''' <version>0.0.0.4</version>
|
|
|
|
|
''' <date>02.10.2018</date>
|
|
|
|
|
''' <summary>
|
|
|
|
|
''' MODULE: LogConfig
|
|
|
|
|
'''
|
|
|
|
|
''' VERSION: 0.0.0.3
|
|
|
|
|
'''
|
|
|
|
|
''' DATE: 02.10.2018
|
|
|
|
|
'''
|
|
|
|
|
''' DESCRIPTION: Module that writes file-logs to different locations:
|
|
|
|
|
''' local application data, the current directory or a custom path.
|
|
|
|
|
''' Files and directories will be automatically created.
|
|
|
|
|
'''
|
|
|
|
|
''' Three different logfiles will be generated:
|
|
|
|
|
'''
|
|
|
|
|
''' - Default: Info and Warn Log Levels
|
|
|
|
|
''' - Error: Warn, Error and Fatal Log Level
|
|
|
|
|
''' - Debug: Debug Log Level
|
|
|
|
|
'''
|
|
|
|
|
'''
|
|
|
|
|
''' DEPENDENCIES: NLog, >= 4.5.8
|
|
|
|
|
'''
|
|
|
|
|
''' PARAMETERS: logPath, PathType
|
|
|
|
|
''' The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.
|
|
|
|
|
'''
|
|
|
|
|
''' - AppData: writes to local application data directory
|
|
|
|
|
''' - CurrentDirectory: writes to `Log` directory relative to the current directory
|
|
|
|
|
''' - CustomPath: writes to custom path specified in `customLogPath`
|
|
|
|
|
'''
|
|
|
|
|
''' customLogPath, String (optional)
|
|
|
|
|
''' If `logPath` is set to custom, this defines the custom logPath.
|
|
|
|
|
'''
|
|
|
|
|
''' suffix, String (optional)
|
|
|
|
|
''' If set to anything other than Nothing, extends the logfile name with this suffix.
|
|
|
|
|
'''
|
|
|
|
|
''' PROPERTIES: LogFile, String (readonly)
|
|
|
|
|
''' Returns the full path of the default log file.
|
|
|
|
|
'''
|
|
|
|
|
''' LogPath, String (readonly)
|
|
|
|
|
''' Returns the path to the log directory.
|
|
|
|
|
'''
|
|
|
|
|
''' LogFactory, NLog.LogFactory (readonly)
|
|
|
|
|
''' Returns the LogFactory that is used to create the Logger object
|
|
|
|
|
'''
|
|
|
|
|
''' Debug, Boolean
|
|
|
|
|
''' Determines if the debug log should be written.
|
|
|
|
|
'''
|
|
|
|
|
''' EXAMPLES: Imports DigitalData.Modules.Logging
|
|
|
|
|
'''
|
|
|
|
|
''' Class FooProgram
|
|
|
|
|
''' Private Logger as Logger
|
|
|
|
|
''' Private LogConfig as LogConfig
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub New()
|
|
|
|
|
''' LogConfig = new LogConfig(args)
|
|
|
|
|
''' Logger = LogConfig.GetLogger()
|
|
|
|
|
''' End Sub
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub Bar()
|
|
|
|
|
''' Logger.Info("Baz")
|
|
|
|
|
''' End Sub
|
|
|
|
|
''' End Class
|
|
|
|
|
'''
|
|
|
|
|
''' Class FooLib
|
|
|
|
|
''' Private Logger as NLog.Logger
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub New(LogConfig as LogConfig)
|
|
|
|
|
''' Logger = LogConfig.GetLogger()
|
|
|
|
|
''' End Sub
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub Bar()
|
|
|
|
|
''' Logger.Info("Baz")
|
|
|
|
|
''' End Sub
|
|
|
|
|
''' End Class
|
|
|
|
|
'''
|
|
|
|
|
''' REMARKS: If logpath can not be written to, falls back to temp folder as defined in:
|
|
|
|
|
''' https://docs.microsoft.com/de-de/dotnet/api/system.io.path.gettemppath?view=netframework-4.7.2
|
|
|
|
|
'''
|
|
|
|
|
''' If used in a service, LogPath must be set to CustomPath, otherwise the Log will be written to System32!
|
|
|
|
|
'''
|
|
|
|
|
''' For NLog Troubleshooting, set the following Environment variables to write the NLog internal Log:
|
|
|
|
|
''' - NLOG_INTERNAL_LOG_LEVEL: Debug
|
|
|
|
|
''' - NLOG_INTERNAL_LOG_FILE: ex. C:\Temp\Nlog_Internal.log
|
|
|
|
|
''' Module that writes file-logs to different locations:
|
|
|
|
|
''' local application data, the current directory or a custom path.
|
|
|
|
|
''' Files and directories will be automatically created.
|
|
|
|
|
''' </summary>
|
|
|
|
|
''' <dependencies>
|
|
|
|
|
''' NLog, >= 4.5.8
|
|
|
|
|
''' </dependencies>
|
|
|
|
|
''' <params>
|
|
|
|
|
''' logPath, PathType
|
|
|
|
|
''' The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.
|
|
|
|
|
'''
|
|
|
|
|
''' - AppData: writes to local application data directory
|
|
|
|
|
''' - CurrentDirectory: writes to `Log` directory relative to the current directory
|
|
|
|
|
''' - CustomPath: writes to custom path specified in `customLogPath`
|
|
|
|
|
'''
|
|
|
|
|
''' customLogPath, String (optional)
|
|
|
|
|
''' If `logPath` is set to custom, this defines the custom logPath.
|
|
|
|
|
'''
|
|
|
|
|
''' suffix, String (optional)
|
|
|
|
|
''' If set to anything other than Nothing, extends the logfile name with this suffix.
|
|
|
|
|
''' </params>
|
|
|
|
|
''' <props>
|
|
|
|
|
''' LogFile, String (readonly)
|
|
|
|
|
''' Returns the full path of the default log file.
|
|
|
|
|
'''
|
|
|
|
|
''' LogPath, String (readonly)
|
|
|
|
|
''' Returns the path to the log directory.
|
|
|
|
|
'''
|
|
|
|
|
''' LogFactory, NLog.LogFactory (readonly)
|
|
|
|
|
''' Returns the LogFactory that is used to create the Logger object
|
|
|
|
|
'''
|
|
|
|
|
''' Debug, Boolean
|
|
|
|
|
''' Determines if the debug log should be written.
|
|
|
|
|
''' </props>
|
|
|
|
|
''' <example>
|
|
|
|
|
''' Imports DigitalData.Modules.Logging
|
|
|
|
|
'''
|
|
|
|
|
''' Class FooProgram
|
|
|
|
|
''' Private Logger as Logger
|
|
|
|
|
''' Private LogConfig as LogConfig
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub New()
|
|
|
|
|
''' LogConfig = new LogConfig(args)
|
|
|
|
|
''' Logger = LogConfig.GetLogger()
|
|
|
|
|
''' End Sub
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub Bar()
|
|
|
|
|
''' Logger.Info("Baz")
|
|
|
|
|
''' End Sub
|
|
|
|
|
''' End Class
|
|
|
|
|
'''
|
|
|
|
|
''' Class FooLib
|
|
|
|
|
''' Private Logger as NLog.Logger
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub New(LogConfig as LogConfig)
|
|
|
|
|
''' Logger = LogConfig.GetLogger()
|
|
|
|
|
''' End Sub
|
|
|
|
|
'''
|
|
|
|
|
''' Public Sub Bar()
|
|
|
|
|
''' Logger.Info("Baz")
|
|
|
|
|
''' End Sub
|
|
|
|
|
''' End Class
|
|
|
|
|
''' </example>
|
|
|
|
|
''' <remarks>
|
|
|
|
|
''' If logpath can not be written to, falls back to temp folder as defined in:
|
|
|
|
|
''' https://docs.microsoft.com/de-de/dotnet/api/system.io.path.gettemppath?view=netframework-4.7.2
|
|
|
|
|
'''
|
|
|
|
|
''' If used in a service, LogPath must be set to CustomPath, otherwise the Log will be written to System32!
|
|
|
|
|
'''
|
|
|
|
|
''' For NLog Troubleshooting, set the following Environment variables to write the NLog internal Log:
|
|
|
|
|
''' - NLOG_INTERNAL_LOG_LEVEL: Debug
|
|
|
|
|
''' - NLOG_INTERNAL_LOG_FILE: ex. C:\Temp\Nlog_Internal.log
|
|
|
|
|
''' </remarks>
|
|
|
|
|
Public Class LogConfig
|
|
|
|
|
Private Const KEEP_FILES_OPEN As Boolean = False
|
|
|
|
|
' MAX_ARCHIVES_FILES works like this (in version 4.5.8):
|
|
|
|
|
@@ -161,7 +156,7 @@ Public Class LogConfig
|
|
|
|
|
End Property
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
''' Initializes a new Logger for a specific `Product` and optinally a filename-suffix.
|
|
|
|
|
''' Initializes a new LogConfig object with a logpath and optinally a filename-suffix.
|
|
|
|
|
''' </summary>
|
|
|
|
|
''' <param name="logPath">The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.</param>
|
|
|
|
|
''' <param name="customLogPath">If `logPath` is set to custom, this defines the custom logPath.</param>
|
|
|
|
|
|