2026-05-19 1.1.16 Corrección multiplataforma tsNotificacionesClient

This commit is contained in:
2026-05-19 18:04:18 +02:00
parent 29e7358184
commit 554bd9d8c3
2 changed files with 34 additions and 36 deletions

View File

@@ -1,12 +1,13 @@
Imports System.Configuration Imports System.Configuration
Imports System.Diagnostics
Imports System.IO Imports System.IO
Imports System.Net Imports System.Net
Imports System.Net.Http Imports System.Net.Http
Imports System.Net.Http.Headers Imports System.Net.Http.Headers
Imports System.Net.Http.Json Imports System.Net.Http.Json
Imports System.Runtime.InteropServices
Imports Microsoft.Extensions.Configuration Imports Microsoft.Extensions.Configuration
Imports Microsoft.Extensions.Logging Imports Microsoft.Extensions.Logging
Imports System.Diagnostics
Public Class TsNotificacionesClient Public Class TsNotificacionesClient
@@ -15,16 +16,20 @@ Public Class TsNotificacionesClient
' ============================================================ ' ============================================================
Private NotInheritable Class LogProvider Private NotInheritable Class LogProvider
Private Shared ReadOnly _factory As ILoggerFactory = LoggerFactory.Create( Private Shared ReadOnly _factory As ILoggerFactory = LoggerFactory.Create(
Sub(builder) Sub(builder)
builder.AddConsole() ' Linux → journald builder.AddConsole() ' Linux → OK
builder.AddEventLog() ' Windows → Event Viewer
End Sub) If OperatingSystem.IsWindows() Then
builder.AddEventLog() ' Solo Windows
End If
End Sub)
Public Shared Function CreateLogger(Of T)() As ILogger(Of T) Public Shared Function CreateLogger(Of T)() As ILogger(Of T)
Return _factory.CreateLogger(Of T)() Return _factory.CreateLogger(Of T)()
End Function End Function
End Class End Class
' ============================================================ ' ============================================================
' CAMPOS DE INSTANCIA ' CAMPOS DE INSTANCIA
' ============================================================ ' ============================================================
@@ -61,40 +66,32 @@ Public Class TsNotificacionesClient
Dim apiKey = If(config("TsNotificaciones:ApiKey"), String.Empty) Dim apiKey = If(config("TsNotificaciones:ApiKey"), String.Empty)
Dim nombreServidor = If(config("TsNotificaciones:NombreServidor"), Environment.MachineName) Dim nombreServidor = If(config("TsNotificaciones:NombreServidor"), Environment.MachineName)
Dim EsWindows = OperatingSystem.IsWindows()
If IncluirMensajeEnLogDelSistema Then If IncluirMensajeEnLogDelSistema AndAlso RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then
' ============================================================ ' --- WINDOWS: Event Viewer ---
' LOGGING MULTIPLATAFORMA Dim ele As EventLogEntryType
' ============================================================ Select Case Tipo
If EsWindows Then Case TipoNotificacionEnum.INFO
' --- WINDOWS: Event Viewer --- ele = EventLogEntryType.Information
Case TipoNotificacionEnum.ADVERTENCIA
ele = EventLogEntryType.Warning
Case TipoNotificacionEnum.ERROR, TipoNotificacionEnum.CRÍTICO
ele = EventLogEntryType.Error
End Select
EventLog.WriteEntry(".NET Runtime", $"{Aplicacion} {titulo} {descripcion}", ele, 1000)
Dim ele As EventLogEntryType ElseIf IncluirMensajeEnLogDelSistema Then
Select Case Tipo ' --- LINUX: ILogger → journald ---
Case TipoNotificacionEnum.INFO Select Case Tipo
ele = EventLogEntryType.Information Case TipoNotificacionEnum.INFO
Case TipoNotificacionEnum.ADVERTENCIA logger.LogInformation($"{titulo} {descripcion}")
ele = EventLogEntryType.Warning Case TipoNotificacionEnum.ADVERTENCIA
Case TipoNotificacionEnum.ERROR, TipoNotificacionEnum.CRÍTICO logger.LogWarning($"{titulo} {descripcion}")
ele = EventLogEntryType.Error Case TipoNotificacionEnum.ERROR, TipoNotificacionEnum.CRÍTICO
End Select logger.LogError($"{titulo} {descripcion}")
End Select
EventLog.WriteEntry(".NET Runtime", $"{Aplicacion} {titulo} {descripcion}", ele, 1000)
Else
' --- LINUX: ILogger → journald ---
Select Case Tipo
Case TipoNotificacionEnum.INFO
logger.LogInformation($"{titulo} {descripcion}")
Case TipoNotificacionEnum.ADVERTENCIA
logger.LogWarning($"{titulo} {descripcion}")
Case TipoNotificacionEnum.ERROR, TipoNotificacionEnum.CRÍTICO
logger.LogError($"{titulo} {descripcion}")
End Select
End If
End If End If
' ============================================================ ' ============================================================

View File

@@ -16,11 +16,12 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<PackageId>tsUtilidades</PackageId> <PackageId>tsUtilidades</PackageId>
<PackageTags>net8.0, libreria</PackageTags> <PackageTags>net8.0, libreria</PackageTags>
<Version>1.1.15</Version> <Version>1.1.16</Version>
<Authors>Manuel</Authors> <Authors>Manuel</Authors>
<Company>Tecnosis S.A</Company> <Company>Tecnosis S.A</Company>
<Description>Utilidades Varias</Description> <Description>Utilidades Varias</Description>
<PackageReleaseNotes> <PackageReleaseNotes>
- 2026-05-19 1.1.16 Corrección multiplataforma tsNotificacionesClient
- 2026-05-12 1.1.15 Se corrige tsNotificacionesClient - 2026-05-12 1.1.15 Se corrige tsNotificacionesClient
- 2026-04-10 1.1.14 Se corrige tsNotificacionesClient - 2026-04-10 1.1.14 Se corrige tsNotificacionesClient
- 2026-04-10 1.1.13 Se corrige tsNotificacionesClient - 2026-04-10 1.1.13 Se corrige tsNotificacionesClient