Add LogTarget
This commit is contained in:
parent
1454650156
commit
1962ab2ead
4 changed files with 14 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
public class BadLogger
|
||||
{
|
||||
public void Log(string message, LogType logType, Exception? ex)
|
||||
public void Log(string message, LogType logType, LogTarget target, Exception? ex)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow:s} [{logType.ToString().ToUpper()}] {message}");
|
||||
|
||||
|
|
6
Facade/LogTarget.cs
Normal file
6
Facade/LogTarget.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
public enum LogTarget
|
||||
{
|
||||
Console = 0,
|
||||
File = 1,
|
||||
Slack = 2
|
||||
}
|
|
@ -8,16 +8,16 @@ public class Logger : ILogger
|
|||
|
||||
public void Information(string message)
|
||||
{
|
||||
_logger.Log(message, LogType.Info, null);
|
||||
_logger.Log(message, LogType.Info, LogTarget.Console, null);
|
||||
}
|
||||
|
||||
public void Error(string message, Exception? ex = null)
|
||||
{
|
||||
_logger.Log(message, LogType.Error, ex);
|
||||
_logger.Log(message, LogType.Error, LogTarget.Console, ex);
|
||||
}
|
||||
|
||||
public void Fatal(string message, Exception? ex = null)
|
||||
{
|
||||
_logger.Log(message, LogType.Fatal, ex);
|
||||
_logger.Log(message, LogType.Fatal, LogTarget.Console, ex);
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@
|
|||
// Using the bad logger
|
||||
var badLogger = new BadLogger();
|
||||
|
||||
badLogger.Log("This is an information message", LogType.Info, null);
|
||||
badLogger.Log("This is an error message", LogType.Error, null);
|
||||
badLogger.Log("This is an information message", LogType.Info, LogTarget.Console, null);
|
||||
badLogger.Log("This is an error message", LogType.Error, LogTarget.Console, null);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ try
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
badLogger.Log("This is an error message with exception", LogType.Error, ex);
|
||||
badLogger.Log("This is an error message with exception", LogType.Error, LogTarget.Console, ex);
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -21,7 +21,7 @@ try
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
badLogger.Log("This is a fatal error message", LogType.Fatal, ex);
|
||||
badLogger.Log("This is a fatal error message", LogType.Fatal, LogTarget.Console, ex);
|
||||
}
|
||||
|
||||
// Using the good logger
|
||||
|
|
Loading…
Reference in a new issue