Logging: Version 0.0.1.0
When debug is enabled, save logs to memory at LogConfig.Logs
This commit is contained in:
parent
e42638fb21
commit
15aa68c3ef
@ -4,7 +4,7 @@ Imports NLog.Config
|
|||||||
Imports NLog.Targets
|
Imports NLog.Targets
|
||||||
|
|
||||||
''' <module>LogConfig</module>
|
''' <module>LogConfig</module>
|
||||||
''' <version>0.0.0.7</version>
|
''' <version>0.0.1.0</version>
|
||||||
''' <date>02.10.2018</date>
|
''' <date>02.10.2018</date>
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Module that writes file-logs to different locations:
|
''' Module that writes file-logs to different locations:
|
||||||
@ -100,6 +100,7 @@ Public Class LogConfig
|
|||||||
Private Const TARGET_ERROR As String = "errorTarget"
|
Private Const TARGET_ERROR As String = "errorTarget"
|
||||||
Private Const TARGET_DETAIL As String = "detailTarget"
|
Private Const TARGET_DETAIL As String = "detailTarget"
|
||||||
Private Const TARGET_DEBUG As String = "debugTarget"
|
Private Const TARGET_DEBUG As String = "debugTarget"
|
||||||
|
Private Const TARGET_MEMORY As String = "memoryTarget"
|
||||||
|
|
||||||
Private Const DATE_FORMAT_LONG As String = "${longdate}"
|
Private Const DATE_FORMAT_LONG As String = "${longdate}"
|
||||||
Private Const DATE_FORMAT_DEFAULT As String = "${date:format=yyyy-MM-dd HH\:mm\:ss}"
|
Private Const DATE_FORMAT_DEFAULT As String = "${date:format=yyyy-MM-dd HH\:mm\:ss}"
|
||||||
@ -110,6 +111,7 @@ Public Class LogConfig
|
|||||||
Private Const LOG_FORMAT_DEFAULT As String = LOG_FORMAT_BASE & " >> ${message}"
|
Private Const LOG_FORMAT_DEFAULT As String = LOG_FORMAT_BASE & " >> ${message}"
|
||||||
Private Const LOG_FORMAT_EXCEPTION As String = LOG_FORMAT_BASE & " >> ${exception:format=Message}${newline}${exception:format=StackTrace}"
|
Private Const LOG_FORMAT_EXCEPTION As String = LOG_FORMAT_BASE & " >> ${exception:format=Message}${newline}${exception:format=StackTrace}"
|
||||||
Private Const LOG_FORMAT_DEBUG As String = LOG_FORMAT_BASE_LONG_DATE & " >> ${message}"
|
Private Const LOG_FORMAT_DEBUG As String = LOG_FORMAT_BASE_LONG_DATE & " >> ${message}"
|
||||||
|
Private Const LOG_FORMAT_MEMORY As String = "${message}${newline}${exception:format=Message}${newline}${exception:format=StackTrace}"
|
||||||
|
|
||||||
Private Const FOLDER_NAME_LOG = "Log"
|
Private Const FOLDER_NAME_LOG = "Log"
|
||||||
Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt"
|
Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt"
|
||||||
@ -158,6 +160,22 @@ Public Class LogConfig
|
|||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Returns Logs in Memory as List(Of String) if Debug is enabled
|
||||||
|
''' Returns nothing if debug is disabled
|
||||||
|
''' </summary>
|
||||||
|
''' <returns>A list of log messages</returns>
|
||||||
|
Public ReadOnly Property Logs As List(Of String)
|
||||||
|
Get
|
||||||
|
If Debug = False Then
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oTarget = config.FindTargetByName(Of MemoryTarget)(TARGET_MEMORY)
|
||||||
|
Return oTarget?.Logs.ToList()
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Initializes a new LogConfig object with a logpath and optinally a filename-suffix.
|
''' Initializes a new LogConfig object with a logpath and optinally a filename-suffix.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
@ -288,6 +306,7 @@ Public Class LogConfig
|
|||||||
config.AddTarget(TARGET_ERROR, GetErrorLogTarget(basePath))
|
config.AddTarget(TARGET_ERROR, GetErrorLogTarget(basePath))
|
||||||
config.AddTarget(TARGET_DEFAULT, GetDefaultLogTarget(basePath))
|
config.AddTarget(TARGET_DEFAULT, GetDefaultLogTarget(basePath))
|
||||||
config.AddTarget(TARGET_DEBUG, GetDebugLogTarget(basePath))
|
config.AddTarget(TARGET_DEBUG, GetDebugLogTarget(basePath))
|
||||||
|
config.AddTarget(TARGET_MEMORY, GetMemoryDebugTarget())
|
||||||
|
|
||||||
' Add default rules
|
' Add default rules
|
||||||
AddDefaultRules(config)
|
AddDefaultRules(config)
|
||||||
@ -333,6 +352,7 @@ Public Class LogConfig
|
|||||||
' Add debug rule, if configured
|
' Add debug rule, if configured
|
||||||
If Debug Then
|
If Debug Then
|
||||||
config.AddRuleForOneLevel(LogLevel.Debug, TARGET_DEBUG)
|
config.AddRuleForOneLevel(LogLevel.Debug, TARGET_DEBUG)
|
||||||
|
config.AddRuleForAllLevels(TARGET_MEMORY)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Reload all running loggers
|
' Reload all running loggers
|
||||||
@ -402,5 +422,15 @@ Public Class LogConfig
|
|||||||
|
|
||||||
Return debugLog
|
Return debugLog
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Private Function GetMemoryDebugTarget() As MemoryTarget
|
||||||
|
Dim memoryLog As New MemoryTarget() With {
|
||||||
|
.Layout = LOG_FORMAT_MEMORY,
|
||||||
|
.Name = TARGET_MEMORY,
|
||||||
|
.OptimizeBufferReuse = True
|
||||||
|
}
|
||||||
|
|
||||||
|
Return memoryLog
|
||||||
|
End Function
|
||||||
#End Region
|
#End Region
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
|||||||
' übernehmen, indem Sie "*" eingeben:
|
' übernehmen, indem Sie "*" eingeben:
|
||||||
' <Assembly: AssemblyVersion("1.0.*")>
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
<Assembly: AssemblyVersion("0.0.0.7")>
|
<Assembly: AssemblyVersion("0.0.1.0")>
|
||||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user