Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 25, 2015 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/cd8e4a72a2ee4b866580 to your computer and use it in GitHub Desktop.
Save Fhernd/cd8e4a72a2ee4b866580 to your computer and use it in GitHub Desktop.
Procesamiento de un archivo de log en C#.
// 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