Skip to content

Commit 5f13b1a

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] Logger wrapper support string formatting.
1 parent 997d4c4 commit 5f13b1a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

algorithm-exercises-csharp-base/src/Logger.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace algorithm_exercises_csharp;
55

66
public sealed class LoggerSingleton
77
{
8-
private static readonly Lazy<LoggerSingleton> _instance = new Lazy<LoggerSingleton>(() => new LoggerSingleton());
8+
private static readonly Lazy<LoggerSingleton> _instance = new(() => new LoggerSingleton());
99

1010
public static LoggerSingleton Instance => _instance.Value;
1111

@@ -26,7 +26,7 @@ private LoggerSingleton()
2626
{
2727
builder
2828
.AddConsole()
29-
.SetMinimumLevel(logLevel); // Configura el nivel mínimo de logging
29+
.SetMinimumLevel(logLevel); // set minimum logging level
3030
});
3131

3232
Logger = loggerFactory.CreateLogger("GlobalLogger");
@@ -47,23 +47,31 @@ public static ILogger getLogger()
4747
return LoggerSingleton.Instance.Logger;
4848
}
4949

50-
public static void info(string message)
50+
public static void info(string message, params object?[] args)
5151
{
52-
LoggerSingleton.Instance.Logger.LogInformation(message);
52+
#pragma warning disable CA2254 // Template should be a static expression
53+
LoggerSingleton.Instance.Logger.LogInformation(message, args);
54+
#pragma warning restore CA2254 // Template should be a static expression
5355
}
5456

55-
public static void warning(string message)
57+
public static void warning(string message, params object?[] args)
5658
{
59+
#pragma warning disable CA2254 // Template should be a static expression
5760
LoggerSingleton.Instance.Logger.LogWarning(message);
61+
#pragma warning restore CA2254 // Template should be a static expression
5862
}
5963

60-
public static void error(string message)
64+
public static void error(string message, params object?[] args)
6165
{
66+
#pragma warning disable CA2254 // Template should be a static expression
6267
LoggerSingleton.Instance.Logger.LogError(message);
68+
#pragma warning restore CA2254 // Template should be a static expression
6369
}
6470

65-
public static void debug(string message)
71+
public static void debu(string message, params object?[] args)
6672
{
73+
#pragma warning disable CA2254 // Template should be a static expression
6774
LoggerSingleton.Instance.Logger.LogDebug(message);
75+
#pragma warning restore CA2254 // Template should be a static expression
6876
}
6977
}

0 commit comments

Comments
 (0)