diff --git a/algorithm-exercises-csharp-base/src/Logger.cs b/algorithm-exercises-csharp-base/src/Logger.cs index 7350307..bff9c3b 100644 --- a/algorithm-exercises-csharp-base/src/Logger.cs +++ b/algorithm-exercises-csharp-base/src/Logger.cs @@ -5,7 +5,7 @@ namespace algorithm_exercises_csharp; public sealed class LoggerSingleton { - private static readonly Lazy _instance = new Lazy(() => new LoggerSingleton()); + private static readonly Lazy _instance = new(() => new LoggerSingleton()); public static LoggerSingleton Instance => _instance.Value; @@ -26,7 +26,7 @@ private LoggerSingleton() { builder .AddConsole() - .SetMinimumLevel(logLevel); // Configura el nivel mínimo de logging + .SetMinimumLevel(logLevel); // set minimum logging level }); Logger = loggerFactory.CreateLogger("GlobalLogger"); @@ -47,23 +47,31 @@ public static ILogger getLogger() return LoggerSingleton.Instance.Logger; } - public static void info(string message) + public static void info(string message, params object?[] args) { - LoggerSingleton.Instance.Logger.LogInformation(message); +#pragma warning disable CA2254 // Template should be a static expression + LoggerSingleton.Instance.Logger.LogInformation(message, args); +#pragma warning restore CA2254 // Template should be a static expression } - public static void warning(string message) + public static void warning(string message, params object?[] args) { +#pragma warning disable CA2254 // Template should be a static expression LoggerSingleton.Instance.Logger.LogWarning(message); +#pragma warning restore CA2254 // Template should be a static expression } - public static void error(string message) + public static void error(string message, params object?[] args) { +#pragma warning disable CA2254 // Template should be a static expression LoggerSingleton.Instance.Logger.LogError(message); +#pragma warning restore CA2254 // Template should be a static expression } - public static void debug(string message) + public static void debu(string message, params object?[] args) { +#pragma warning disable CA2254 // Template should be a static expression LoggerSingleton.Instance.Logger.LogDebug(message); +#pragma warning restore CA2254 // Template should be a static expression } } diff --git a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs index bcc9356..2e01288 100644 --- a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs +++ b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs @@ -11,7 +11,10 @@ protected Euler002() { } public static int fiboEvenSum(int n) { - int total = 0; + Log.info("fiboEvenSum({n})", n); + + int i = 0; + int even_sum = 0; int fibo; int fibo1 = 1; int fibo2 = 1; @@ -19,16 +22,22 @@ public static int fiboEvenSum(int n) while (fibo1 + fibo2 < n) { fibo = fibo1 + fibo2; - fibo1 = fibo2; - fibo2 = fibo; + + Log.info("Fibonacci({i}) = {fibo}", i, fibo); if (fibo % 2 == 0) { - total += fibo; + even_sum += fibo; } + + fibo1 = fibo2; + fibo2 = fibo; + i += 1; } - return total; + Log.info("Problem 0002 result: {even_sum}", even_sum); + + return even_sum; } // Function to find the sum of all multiples of a and b below n