jj: Use NLog GetClassFullName to determine logger name

This commit is contained in:
Jonathan Jenne 2018-10-24 15:40:37 +02:00
parent a7df0b57e4
commit b2bc096837

View File

@ -214,9 +214,6 @@ Public Class LogConfig
.Configuration = config
}
Dim l = LogFactory.GetCurrentClassLogger(Of Logger)()
' Save log paths for files/directory
LogDirectory = basePath
LogFile = GetCurrentLogFilePath()
@ -227,15 +224,41 @@ Public Class LogConfig
''' </summary>
''' <returns>An object of Logging.Logger</returns>
Public Function GetLogger() As Logger
Dim name As String = "Unknown"
Try
Dim frame As New StackFrame(1)
Dim method = frame.GetMethod()
name = method.DeclaringType.FullName
Catch ex As Exception
End Try
Dim oClassName As String = GetClassFullName()
Return LogFactory.GetLogger(Of Logger)(oClassName)
End Function
Return LogFactory.GetLogger(Of Logger)(name)
''' <summary>
''' Gets the fully qualified name of the class invoking the calling method,
''' including the namespace but Not the assembly.
''' </summary>
''' <returns>The fully qualified class name</returns>
''' <remarks>This method is very resource-intensive!</remarks>
Public Shared Function GetClassFullName() As String
Dim oFramesToSkip As Integer = 2
Dim oClassName As String = String.Empty
Dim oStackTrace = Environment.StackTrace
Dim oStackTraceLines = oStackTrace.Replace(vbCr, "").Split({vbLf}, StringSplitOptions.RemoveEmptyEntries)
For i As Integer = 0 To oStackTraceLines.Length - 1
Dim oCallingClassAndMethod = oStackTraceLines(i).Split({" ", "<>", "(", ")"}, StringSplitOptions.RemoveEmptyEntries)(1)
Dim oMethodStartIndex As Integer = oCallingClassAndMethod.LastIndexOf(".", StringComparison.Ordinal)
If oMethodStartIndex > 0 Then
Dim oCallingClass = oCallingClassAndMethod.Substring(0, oMethodStartIndex)
oClassName = oCallingClass.TrimEnd("."c)
If Not oClassName.StartsWith("System.Environment") AndAlso oFramesToSkip <> 0 Then
i += oFramesToSkip - 1
oFramesToSkip = 0
Continue For
End If
If Not oClassName.StartsWith("System.") Then Exit For
End If
Next
Return oClassName
End Function
''' <summary>