86 lines
4.6 KiB
C#
86 lines
4.6 KiB
C#
using bdAsegasa;
|
|
using bdAsegasa.db;
|
|
using Microsoft.VisualBasic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
|
|
namespace Servicio_Gestion_Asegasa
|
|
{
|
|
public class Logs
|
|
{
|
|
private static object oBloqueoLog;
|
|
//private static EventLog el;
|
|
public static async Task AñadeLogAsync(tsUtilidades.Enumeraciones.TipoLog Tipo, string Mensaje, Exception e = null)
|
|
{
|
|
// ----------------------------------------------------------------------------------------------------
|
|
// Descripción Sub: Gestión de logs de la aplicación
|
|
// Fecha. Creacion: ???
|
|
// Creada por: manmog
|
|
// Ultima Modificacion: 24/11/2010
|
|
//
|
|
// Modificaciones:
|
|
// ===============
|
|
if (oBloqueoLog == null) oBloqueoLog = new object();
|
|
lock (oBloqueoLog)
|
|
{
|
|
try
|
|
{
|
|
if (e != null)
|
|
{
|
|
|
|
string sStackTrace = "Tipo excepción: " + e.ToString() + Constants.vbCrLf;
|
|
Exception exError = e;
|
|
do
|
|
{
|
|
sStackTrace += exError.StackTrace + Constants.vbCrLf;
|
|
exError = exError.InnerException;
|
|
}
|
|
while (!Information.IsNothing(exError));
|
|
if (sStackTrace != "")
|
|
Mensaje += Constants.vbCrLf + "|StackTrace: " + sStackTrace;
|
|
}
|
|
switch (Tipo)
|
|
{
|
|
case tsUtilidades.Enumeraciones.TipoLog.Fallo:
|
|
Mensaje = "Error WSAsegasa. " + " Enviado desde " + Environment.MachineName + ". Version:" + Assembly.GetEntryAssembly()?.GetName().Version + ". Mensaje: " + Mensaje;
|
|
Log.Fatal(Mensaje);
|
|
tsUtilidades.TsNotificacionesClient.RegistrarAsync("Error en Servicio Gestion Asegasa", Mensaje, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
break;
|
|
case tsUtilidades.Enumeraciones.TipoLog.Advertencia:
|
|
Mensaje = "Advertencia WSAsegasa. " + " Enviado desde " + Environment.MachineName + ". Version:" + Assembly.GetEntryAssembly()?.GetName().Version + ". " + Mensaje;
|
|
Log.Warning(Mensaje);
|
|
tsUtilidades.TsNotificacionesClient.RegistrarAsync("Advertencia en Servicio Gestion Asegasa", Mensaje, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ADVERTENCIA);
|
|
break;
|
|
case tsUtilidades.Enumeraciones.TipoLog.InicioServicio:
|
|
Mensaje = "Inicio WSAsegasa. " + " Enviado desde " + Environment.MachineName + ". Version:" + Assembly.GetEntryAssembly()?.GetName().Version + ". Mensaje: " + Mensaje;
|
|
Log.Information(Mensaje);
|
|
tsUtilidades.TsNotificacionesClient.RegistrarAsync("Inicio Servicio Gestion Asegasa", Mensaje, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.INFO);
|
|
break;
|
|
case tsUtilidades.Enumeraciones.TipoLog.FinServicio:
|
|
Mensaje = "Finalización WSAsegasa. " + " Enviado desde " + Environment.MachineName + ". Version:" + Assembly.GetEntryAssembly()?.GetName().Version + ". Mensaje: " + Mensaje;
|
|
Log.Information(Mensaje);
|
|
tsUtilidades.TsNotificacionesClient.RegistrarAsync("Finalización Servicio Gestion Asegasa", Mensaje, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.INFO);
|
|
break;
|
|
default:
|
|
Mensaje = Tipo.ToString() + " WSAsegasa. " + " Enviado desde " + Environment.MachineName + ". Version:" + Assembly.GetEntryAssembly()?.GetName().Version + ". " + Mensaje;
|
|
Log.Information(Mensaje);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (e != null)
|
|
Mensaje += " --- " + e.StackTrace;
|
|
|
|
Log.Fatal(Mensaje + " ---" + ex.Message + " --- " + ex.StackTrace);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|