Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save javierguerrero/dd1ae4dd1cf44f263a93f04c6e73f801 to your computer and use it in GitHub Desktop.
Save javierguerrero/dd1ae4dd1cf44f263a93f04c6e73f801 to your computer and use it in GitHub Desktop.
exception_handling_csharp_chapter6_6.cs
using Serilog;
class Program
{
static void Main()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
try
{
EjecutarOperacion();
}
catch (Exception ex)
{
Log.Error(ex, "Error inesperado en EjecutarOperacion");
Console.WriteLine("Ocurrió un error: " + ex.Message);
}
finally
{
Log.CloseAndFlush();
}
}
static void EjecutarOperacion()
{
// Simulación de un error
throw new InvalidOperationException("Operación no válida");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment