Agregar archivos de proyecto.
This commit is contained in:
144
bdGrupoSanchoToro/Utilidades.cs
Normal file
144
bdGrupoSanchoToro/Utilidades.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualBasic;
|
||||
using bdGrupoSanchoToro.db;
|
||||
using bdGrupoSanchoToro.dbcontext;
|
||||
|
||||
namespace bdGrupoSanchoToro.db
|
||||
{
|
||||
|
||||
|
||||
public class Utilidades
|
||||
{
|
||||
public static empresas? EmpresaActual;
|
||||
public static string Usuario;
|
||||
|
||||
public static int idUsuario;
|
||||
public static usuarios UsuarioActual;
|
||||
public static string VersionPrograma { get; set; }
|
||||
// public static double PorcentajeIva { get; set; }
|
||||
|
||||
|
||||
|
||||
public static EventLog el;
|
||||
public static string DirectorioLogs;
|
||||
private static object oBloqueoLog = new object();
|
||||
public static void AñadeLog(tsUtilidades.Enumeraciones.TipoLog Tipo, string Asunto, 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:
|
||||
// ===============
|
||||
|
||||
lock (oBloqueoLog)
|
||||
{
|
||||
GrupoSanchoToroContext ctx;
|
||||
|
||||
string sFicheroLog = DirectorioLogs + "Log-" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + ".txt";
|
||||
try
|
||||
{
|
||||
if (!(e == null))
|
||||
{
|
||||
if (el is not null)
|
||||
el.WriteEntry(e.Message + Constants.vbCrLf + e.StackTrace, EventLogEntryType.Error);
|
||||
string sStackTrace = "Tipo excepción: " + e.ToString() + Constants.vbCrLf;
|
||||
var exError = e;
|
||||
do
|
||||
{
|
||||
sStackTrace += exError.StackTrace + Constants.vbCrLf;
|
||||
exError = exError.InnerException;
|
||||
}
|
||||
while (exError != null);
|
||||
if (!string.IsNullOrEmpty(sStackTrace))
|
||||
Mensaje += Constants.vbCrLf + "StackTrace: " + sStackTrace;
|
||||
}
|
||||
switch (Tipo)
|
||||
{
|
||||
case tsUtilidades.Enumeraciones.TipoLog.Fallo:
|
||||
case tsUtilidades.Enumeraciones.TipoLog.Advertencia:
|
||||
{
|
||||
if (Tipo == tsUtilidades.Enumeraciones.TipoLog.Fallo)
|
||||
{
|
||||
sFicheroLog = DirectorioLogs + "Errores-" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + ".txt";
|
||||
Asunto = "Error GrupoSanchoToro. " + ". Version:" + VersionPrograma + ". " + Asunto;
|
||||
Mensaje = "Error GrupoSanchoToro. " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " Enviado desde " + Environment.MachineName + ". Version:" + VersionPrograma + ". Mensaje: " + Mensaje;
|
||||
}
|
||||
else
|
||||
{
|
||||
Asunto = "Advertencia GrupoSanchoToro. " + ". Version:" + VersionPrograma + ". " + Asunto;
|
||||
Mensaje = "Advertencia GrupoSanchoToro. " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " Enviado desde " + Environment.MachineName + ". Version:" + VersionPrograma + ". " + Mensaje;
|
||||
}
|
||||
string sDireccionesEnvio = "manmog@gmail.com";
|
||||
string sServidorSMTP = "smtp.gmail.com";
|
||||
string sRemitente = "administracion@english-skills.net";
|
||||
tsCorreos.Funciones.EnviaCorreo(sServidorSMTP, sRemitente, sDireccionesEnvio, Asunto, Mensaje, null,null, "", "", sRemitente, "", 587, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Anadelogtxt(Mensaje + " --- " + e.StackTrace, sFicheroLog);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sFicheroLog = DirectorioLogs + @"Errores\Errores-" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + ".txt";
|
||||
if (e is not null)
|
||||
Mensaje += " --- " + e.StackTrace;
|
||||
Anadelogtxt(Mensaje + " ---" + ex.Message + " --- " + ex.StackTrace, sFicheroLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Anadelogtxt(string Mensaje, string FicheroLog)
|
||||
{
|
||||
System.IO.StreamWriter sw = null;
|
||||
try
|
||||
{
|
||||
Mensaje = Mensaje.Replace(Constants.vbCrLf, "---");
|
||||
if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(FicheroLog)))
|
||||
tsUtilidades.Utilidades.CreaEstructuraDirectorio(System.IO.Path.GetDirectoryName(FicheroLog));
|
||||
if (System.IO.File.Exists(FicheroLog))
|
||||
{
|
||||
sw = System.IO.File.AppendText(FicheroLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw = System.IO.File.CreateText(FicheroLog);
|
||||
}
|
||||
Mensaje = DateTime.Now.ToString() + "|" + "Ws: " + Process.GetCurrentProcess().WorkingSet64.ToString().PadLeft(20) + " PMS: " + Process.GetCurrentProcess().PrivateMemorySize64.ToString().PadLeft(20) + "|" + Mensaje;
|
||||
|
||||
sw.WriteLine(Mensaje);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string sDireccionesEnvio = "manmog@gmail.com";
|
||||
string sServidorSMTP = "smtp.gmail.com";
|
||||
string sRemitente = "administracion@english-skills.net";
|
||||
// tsCorreos.Funciones.EnviaCorreo(sServidorSMTP, sRemitente, sDireccionesEnvio, Asunto, Mensaje,,,,, "se9608dc.g")
|
||||
tsCorreos.Funciones.EnviaCorreo(sServidorSMTP, sRemitente, sDireccionesEnvio, "Error Anadelogtxt. " + Mensaje, Environment.MachineName + ".- " + ex.Message + Constants.vbCrLf + ex.StackTrace + Constants.vbCrLf + ex.Source, null,null, "", "", sRemitente, "", 587, true);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
sw.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user