Created
November 9, 2024 03:16
-
-
Save javierguerrero/dd1ae4dd1cf44f263a93f04c6e73f801 to your computer and use it in GitHub Desktop.
exception_handling_csharp_chapter6_6.cs
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
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