This file contains hidden or 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
| Log.Logger = new LoggerConfiguration() | |
| .WriteTo.Console() | |
| .CreateLogger(); | |
| try | |
| { | |
| throw new Exception("Error inesperado"); | |
| } | |
| catch (Exception ex) | |
| { |
This file contains hidden or 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
| Log.Logger = new LoggerConfiguration() | |
| .WriteTo.Console() | |
| .WriteTo.Elasticsearch(new Serilog.Sinks.Elasticsearch.ElasticsearchSinkOptions(new Uri("http://localhost:9200")) | |
| { | |
| IndexFormat = "logs-{0:yyyy.MM.dd}", | |
| AutoRegisterTemplate = true, | |
| }) | |
| .CreateLogger(); | |
| try |
This file contains hidden or 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
| public interface ILoggingService | |
| { | |
| void Log(string message); | |
| void LogError(Exception ex); | |
| } | |
| public class CloudLoggingService : ILoggingService | |
| { | |
| public void Log(string message) | |
| { |
This file contains hidden or 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
| public interface ILogger | |
| { | |
| void Log(string message); | |
| void LogError(Exception ex); | |
| } | |
| public class BasicLogger : ILogger | |
| { | |
| public void Log(string message) | |
| { |
This file contains hidden or 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
| Log.Logger = new LoggerConfiguration() | |
| .WriteTo.Console() | |
| .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day) | |
| .CreateLogger(); | |
| try | |
| { | |
| // C贸digo que puede fallar | |
| } | |
| catch (Exception ex) |
This file contains hidden or 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
| try | |
| { | |
| // C贸digo que puede fallar | |
| } | |
| catch (Exception ex) | |
| { | |
| Console.WriteLine($"Mensaje: {ex.Message}"); | |
| Console.WriteLine($"Traza de pila: {ex.StackTrace}"); | |
| if (ex.InnerException != null) | |
| { |
This file contains hidden or 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) |
This file contains hidden or 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
| try | |
| { | |
| MetodoCritico1(); | |
| MetodoCritico2(); | |
| MetodoCritico3(); | |
| } | |
| catch (Exception ex) | |
| { | |
| Console.WriteLine("Error en el c贸digo cr铆tico: " + ex.Message); | |
| } |
This file contains hidden or 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
| public async Task ObtenerDatosAsync() | |
| { | |
| try | |
| { | |
| await RealizarLlamadaAPIAsync(); | |
| } | |
| catch (HttpRequestException ex) | |
| { | |
| Console.WriteLine("Error en la solicitud HTTP: " + ex.Message); | |
| } |
This file contains hidden or 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
| try | |
| { | |
| // C贸digo que puede lanzar una excepci贸n | |
| } | |
| catch (Exception ex) | |
| { | |
| Log.Error(ex, "Error inesperado en la operaci贸n"); | |
| } |
NewerOlder