28 lines
1.3 KiB
VB.net
28 lines
1.3 KiB
VB.net
Imports System.Runtime.CompilerServices
|
|
Imports Microsoft.Extensions.Logging
|
|
|
|
Public Module LoggerExtensions
|
|
'// Ejemplo de uso de la extensión LogVariable():
|
|
'//
|
|
'// ' Registrar información de una variable
|
|
'// Dim peassoVariable As String = "Hello, World!"
|
|
'// logger.LogVariable("peassoVariable", peassoVariable, LogLevel.Debug)
|
|
<Extension()>
|
|
Public Sub LogVariable(ByVal logger As ILogger, variableName As String, variableValue As Object, logLevel As LogLevel)
|
|
Try
|
|
If logger Is Nothing Then Throw New ArgumentNullException(NameOf(logger))
|
|
If variableName Is Nothing Then Throw New ArgumentNullException(NameOf(variableName))
|
|
|
|
Dim variableType As String = If(variableValue IsNot Nothing, variableValue.GetType().FullName, "Null")
|
|
Dim variableContent As String = If(variableValue IsNot Nothing, variableValue.ToString(), "Null")
|
|
|
|
Dim message As String = $"Variable Name: {variableName}, Type: {variableType}, Value: {variableContent}"
|
|
|
|
logger.Log(logLevel, New EventId(), message, exception:=Nothing, Function(s, e) s.ToString())
|
|
Catch ex As Exception
|
|
Debug.WriteLine($"Excepción en LoggerExtensions.LogVariable: {ex}")
|
|
End Try
|
|
End Sub
|
|
|
|
End Module
|