jj: Use NLog GetClassFullName to determine logger name
This commit is contained in:
parent
a7df0b57e4
commit
b2bc096837
@ -214,9 +214,6 @@ Public Class LogConfig
|
|||||||
.Configuration = config
|
.Configuration = config
|
||||||
}
|
}
|
||||||
|
|
||||||
Dim l = LogFactory.GetCurrentClassLogger(Of Logger)()
|
|
||||||
|
|
||||||
|
|
||||||
' Save log paths for files/directory
|
' Save log paths for files/directory
|
||||||
LogDirectory = basePath
|
LogDirectory = basePath
|
||||||
LogFile = GetCurrentLogFilePath()
|
LogFile = GetCurrentLogFilePath()
|
||||||
@ -227,15 +224,41 @@ Public Class LogConfig
|
|||||||
''' </summary>
|
''' </summary>
|
||||||
''' <returns>An object of Logging.Logger</returns>
|
''' <returns>An object of Logging.Logger</returns>
|
||||||
Public Function GetLogger() As Logger
|
Public Function GetLogger() As Logger
|
||||||
Dim name As String = "Unknown"
|
Dim oClassName As String = GetClassFullName()
|
||||||
Try
|
Return LogFactory.GetLogger(Of Logger)(oClassName)
|
||||||
Dim frame As New StackFrame(1)
|
End Function
|
||||||
Dim method = frame.GetMethod()
|
|
||||||
name = method.DeclaringType.FullName
|
|
||||||
Catch ex As Exception
|
|
||||||
End Try
|
|
||||||
|
|
||||||
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
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user