2023-09-04 09:17:26 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
// Using the bad logger
|
|
|
|
|
var badLogger = new BadLogger();
|
|
|
|
|
|
2023-09-05 09:40:56 +00:00
|
|
|
|
badLogger.Log("This is an information message", LogType.Info, LogTarget.Console, null);
|
|
|
|
|
badLogger.Log("This is an error message", LogType.Error, LogTarget.Console, null);
|
2023-09-04 09:17:26 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Something went wrong");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-09-05 09:40:56 +00:00
|
|
|
|
badLogger.Log("This is an error message with exception", LogType.Error, LogTarget.Console, ex);
|
2023-09-04 09:17:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Something went really wrong");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-09-05 09:40:56 +00:00
|
|
|
|
badLogger.Log("This is a fatal error message", LogType.Fatal, LogTarget.Console, ex);
|
2023-09-04 09:17:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Using the good logger
|
|
|
|
|
ILogger logger = new Logger();
|
|
|
|
|
|
|
|
|
|
logger.Information("This is an information message");
|
|
|
|
|
logger.Error("This is an error message");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Something went wrong");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Error("This is an error message with exception", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Something went really wrong");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Fatal("This is a fatal error message", ex);
|
|
|
|
|
}
|