Skip to content

Develop #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions algorithm-exercises-csharp-base/src/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace algorithm_exercises_csharp;

public sealed class LoggerSingleton
{
private static readonly Lazy<LoggerSingleton> _instance = new Lazy<LoggerSingleton>(() => new LoggerSingleton());
private static readonly Lazy<LoggerSingleton> _instance = new(() => new LoggerSingleton());

public static LoggerSingleton Instance => _instance.Value;

Expand All @@ -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");
Expand All @@ -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
}
}
19 changes: 14 additions & 5 deletions algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,33 @@ 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;

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
Expand Down