Created
July 25, 2015 16:23
-
-
Save Fhernd/cd8e4a72a2ee4b866580 to your computer and use it in GitHub Desktop.
Procesamiento de un archivo de log 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.R0525 | |
{ | |
public class SeleccionRegistros | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(Environment.NewLine); | |
// Le todas las entradas en el archivo log_completo.log: | |
Console.WriteLine ("Mostrando todos los registros..."); | |
IEnumerable<string> registros = File.ReadAllLines("log_completo.log"); | |
foreach (string registro in registros) | |
{ | |
Console.WriteLine ("Registro: {0}", registro); | |
} | |
Console.WriteLine ("\nSelección sólo registros de error..."); | |
IEnumerable<string> registrosError = File.ReadLines("log_completo.log").Where( | |
e => e.StartsWith("Error") | |
); | |
foreach (string registroError in registrosError) | |
{ | |
Console.WriteLine ("Registro error: {0}", registroError); | |
} | |
Console.WriteLine(Environment.NewLine); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment