Logging: Remove Warning from Error Log, Add Sublogging with Modules, Revert own Logger methods

This commit is contained in:
Jonathan Jenne
2021-06-17 13:05:29 +02:00
parent 4b7315a5e1
commit 85a33b35e8
2 changed files with 12 additions and 67 deletions

View File

@@ -324,10 +324,15 @@ Public Class LogConfig
End Function
''' <summary>
''' Returns the Logger for the specified module
''' Returns the Logger for the specified module using event-properties
''' </summary>
''' <remarks>
''' https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer
''' https://stackoverflow.com/questions/31337030/separate-log-file-for-specific-class-instance-using-nlog/32065824#32065824
''' </remarks>
''' <returns>An object of Logging.Logger</returns>
Public Function GetLoggerWithModule(ModuleName As String) As Logger
<DebuggerStepThrough()>
Public Function GetLoggerFor(ModuleName As String) As Logger
Dim oClassName As String = GetClassFullName()
Return GetLogger(oClassName, ModuleName)
End Function
@@ -340,7 +345,11 @@ Public Class LogConfig
<DebuggerStepThrough()>
Public Function GetLogger(ClassName As String, ModuleName As String) As Logger
Dim oLogger = LogFactory.GetLogger(Of Logger)(ClassName)
oLogger.ModuleName = ModuleName
If ModuleName IsNot Nothing Then
Return oLogger.WithProperty("ModuleName", $"-{ModuleName}")
End If
Return oLogger
End Function
@@ -431,7 +440,6 @@ Public Class LogConfig
Private Sub AddDefaultRules(ByRef config As LoggingConfiguration)
config.AddRuleForOneLevel(LogLevel.Error, TARGET_ERROR_EX)
config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_ERROR_EX)
config.AddRuleForOneLevel(LogLevel.Warn, TARGET_ERROR)
config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
config.AddRuleForOneLevel(LogLevel.Info, TARGET_DEFAULT)
End Sub