コード例 #1
0
        /// <summary>
        /// Grava a mensagem de log desejada, no nível desejado.
        /// Caso o nível desejado não esteja ativo no momento, nada será gravado.
        /// </summary>
        /// <param name="Mensagem">Mensagem de log a ser gravada.</param>
        /// <param name="Nivel">Nível de log da mensagem sendo gravada.</param>
        /// <param name="SubPasta">Subpasta (opcional) na qual se deseja gravar o log.</param>
        /// <param name="NomeArquivo">Nome do arquivo (opcional) para o qual o log será gravado. Por padrão, o nome é a data, no formato yyyyddmm. A extensão sempre é .txt.</param>
        public static void GravarLog(String Mensagem, NivelLog Nivel, String SubPasta, String NomeArquivo)
        {
            try
            {
                if (EstaGravandoNivel(Nivel))
                {
                    String path = pathPastaLog;
                    String nome = DateTime.Now.ToString("yyyyMMdd");
                    if (SubPasta != "")
                    {
                        path = Path.Combine(pathPastaLog, SubPasta);
                    }
                    if (NomeArquivo != "")
                    {
                        nome = NomeArquivo;
                    }

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    File.AppendAllText(Path.Combine(path, nome + ".txt"), DateTime.Now.ToString("HH:mm:ss") + " - " + Enum.GetName(typeof(NivelLog), Nivel) + " - " + Mensagem + "\r\n");
                }
            }
            catch { }
        }
コード例 #2
0
ファイル: LogNet.cs プロジェクト: berczeck/.Net
        private void Registrar(NivelLog nivelLog, InformacionLog informacionLog)
        {
            LogLevel level = _mapeoNivelError[nivelLog];

            var theEvent =
                new LogEventInfo(level, string.Empty, informacionLog.Mensaje);

            if (informacionLog.Excepcion != null)
            {
                var detalleError = ExceptionHandler.Instancia.RecuperarDetalleError(informacionLog.Excepcion);
                theEvent.Properties["DatosError"] = detalleError;
            }

            var datosAdicionales = informacionLog.DatosAdicionales;

            if (datosAdicionales != null)
            {
                foreach (KeyValuePair <string, object> valor in datosAdicionales)
                {
                    theEvent.Properties[valor.Key] = datosAdicionales[valor.Key];
                }

                if (!datosAdicionales.ContainsKey("EventId"))
                {
                    theEvent.Properties["EventId"] = (Int16)nivelLog;
                }
            }

            var        st = new StackTrace();
            StackFrame sf = st.GetFrame(2);

            var declaringType = sf.GetMethod().DeclaringType;

            if (declaringType != null)
            {
                theEvent.Properties["Modulo"] =
                    declaringType.Module.ScopeName;
                theEvent.Properties["Origen"] =
                    string.Format("{0}.{1}", declaringType.FullName, sf.GetMethod().Name);
            }

            _logger.Log(theEvent);

            if (NotificacionExterna != null)
            {
                NotificacionExterna.Registrar(nivelLog, informacionLog);
            }
        }
コード例 #3
0
 /// <summary>
 /// Grava a mensagem de log desejada, no nível desejado.
 /// Caso o nível desejado não esteja ativo no momento, nada será gravado.
 /// </summary>
 /// <param name="Mensagem">Mensagem de log a ser gravada.</param>
 /// <param name="Nivel">Nível de log da mensagem sendo gravada.</param>
 public static void GravarLog(String Mensagem, NivelLog Nivel)
 {
     GravarLog(Mensagem, Nivel, "", "");
 }
コード例 #4
0
 /// <summary>
 /// Verifica se um nível específico de log está sendo gravado.
 /// </summary>
 /// <param name="Nivel">Nível que se deseja verificar se está sendo gravado.</param>
 /// <returns>Verdadeiro quando estiver sendo gravado o nível especificado, Falso caso contrário.</returns>
 public static Boolean EstaGravandoNivel(NivelLog Nivel)
 {
     return(new List <String>(NiveisLogAtual.Split('|')).Contains(Enum.GetName(typeof(NivelLog), Nivel)));
 }
コード例 #5
0
ファイル: NotificacionLog.cs プロジェクト: berczeck/.Net
 public void Registrar(NivelLog nivelLog, InformacionLog informacionLog)
 {
     Console.WriteLine(informacionLog.Excepcion.Message);
 }
コード例 #6
0
ファイル: LogNet.cs プロジェクト: berczeck/.Net
        private void Registrar(NivelLog nivelLog, InformacionLog informacionLog)
        {
            LogLevel level = _mapeoNivelError[nivelLog];

            var theEvent =
                new LogEventInfo(level, string.Empty, informacionLog.Mensaje);

            if (informacionLog.Excepcion != null)
            {
                var detalleError = ExceptionHandler.Instancia.RecuperarDetalleError(informacionLog.Excepcion);
                theEvent.Properties["DatosError"] = detalleError;
            }

            var datosAdicionales = informacionLog.DatosAdicionales;

            if (datosAdicionales != null)
            {
                foreach (KeyValuePair<string, object> valor in datosAdicionales)
                {
                    theEvent.Properties[valor.Key] = datosAdicionales[valor.Key];
                }

                if (!datosAdicionales.ContainsKey("EventId"))
                {
                    theEvent.Properties["EventId"] = (Int16) nivelLog;
                }
            }

            var st = new StackTrace();
            StackFrame sf = st.GetFrame(2);

            var declaringType = sf.GetMethod().DeclaringType;
            if (declaringType != null)
            {
                theEvent.Properties["Modulo"] =
                    declaringType.Module.ScopeName;
                theEvent.Properties["Origen"] =
                    string.Format("{0}.{1}", declaringType.FullName, sf.GetMethod().Name);
            }
            
            _logger.Log(theEvent);
            
            if (NotificacionExterna != null)
            {
                NotificacionExterna.Registrar(nivelLog, informacionLog);
            }
        }