Created
July 25, 2015 13:12
-
-
Save Fhernd/e377524838d7eef4a9ab to your computer and use it in GitHub Desktop.
Uso de registro de eventos en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OrtizOL - xCSw - http://ortizol.blogspot.com | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace Receta.CSharp.R0524 | |
{ | |
public class FiltroRegistros | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(Environment.NewLine); | |
// Lista con registros de eventos: | |
List<String> registros = new List<String>(); | |
// Adición de entrada de registros: | |
registros.Add("Excepción no. 1"); | |
registros.Add("Excepción no. 2"); | |
registros.Add("Excepción no. 3"); | |
registros.Add("Error no. 1"); | |
registros.Add("Error no. 2"); | |
registros.Add("Error no. 3"); | |
registros.Add("Error no. 4"); | |
registros.Add("Error no. 5"); | |
// Crea archivo de log con todas las entradas: | |
File.WriteAllLines("log_completo.log", registros); | |
// Filtra todos los errores en un nuevo archivo: | |
File.WriteAllLines("log_errores.log", registros.Where( e => e.StartsWith("Error"))); | |
// Muestra el contenido del archivo con todos los registros: | |
Console.WriteLine ("Registro de eventos completo: "); | |
string[] entradas = File.ReadAllLines("log_completo.log"); | |
foreach (string entrada in entradas) | |
{ | |
Console.WriteLine (entrada); | |
} | |
// Muestra sólo los registros de error: | |
Console.WriteLine ("\nRegistros de eventos (sólo errores): "); | |
entradas = File.ReadAllLines("log_errores.log"); | |
foreach (string entrada in entradas) | |
{ | |
Console.WriteLine (entrada); | |
} | |
Console.WriteLine(Environment.NewLine); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment