Skip to content

[REFACTOR] Codefactor issues, fixed. #114

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 1 commit into from
Sep 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;

public class InvalidValueException : Exception
public class RansomNote
{
// constructor for the InvalidAgeException class
public InvalidValueException(string msg)
public class InvalidValueException : Exception
{
Console.WriteLine(msg);
// constructor for the InvalidAgeException class
public InvalidValueException(string msg)
{
Console.WriteLine(msg);
}
}
}

public class RansomNote
{
[ExcludeFromCodeCoverage]
protected RansomNote() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;

using System.Diagnostics.CodeAnalysis;

public class Competition(int _luck, int _important)
{
public int luck => _luck;
public int important => _important;
}

public class LuckBalance
{
public class Competition(int _luck, int _important)
{
public int luck => _luck;
public int important => _important;
}

[ExcludeFromCodeCoverage]
protected LuckBalance() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected Euler003() { }
int i = 2;
while (i <= Math.Sqrt(divisor))
{
if (0 == divisor % i)
if (divisor % i == 0)
{
divisor = divisor / i;
max_prime_factor = divisor;
Expand Down
56 changes: 28 additions & 28 deletions algorithm_exercises_csharp_base/src/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@ namespace algorithm_exercises_csharp;
using Microsoft.Extensions.Logging;
using System;

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

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

public ILogger Logger { get; }
public static LoggerSingleton Instance => _instance.Value;

private LoggerSingleton()
{
// Read the LOG_LEVEL environment variable
var logLevelEnv = Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "Information";
public ILogger Logger { get; }

// Convert the environment variable value to LogLevel
if (!Enum.TryParse<LogLevel>(logLevelEnv, ignoreCase: true, out var logLevel))
private LoggerSingleton()
{
logLevel = LogLevel.Information; // Set the minimum logging level
}
// Read the LOG_LEVEL environment variable
var logLevelEnv = Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "Information";

var loggerFactory = LoggerFactory.Create(builder =>
{
builder
.AddConsole()
.SetMinimumLevel(logLevel); // set minimum logging level
});
// Convert the environment variable value to LogLevel
if (!Enum.TryParse<LogLevel>(logLevelEnv, ignoreCase: true, out var logLevel))
{
logLevel = LogLevel.Information; // Set the minimum logging level
}

Logger = loggerFactory.CreateLogger("GlobalLogger");
var loggerFactory = LoggerFactory.Create(builder =>
{
builder
.AddConsole()
.SetMinimumLevel(logLevel); // set minimum logging level
});

Logger.LogInformation("Initializing");
Logger = loggerFactory.CreateLogger("GlobalLogger");

Logger.LogInformation("Info level enabled");
Logger.LogWarning("Warning level enabled");
Logger.LogError("Error level enabled");
Logger.LogDebug("Debug level enabled");
Logger.LogInformation("Initializing");

Logger.LogInformation("Info level enabled");
Logger.LogWarning("Warning level enabled");
Logger.LogError("Error level enabled");
Logger.LogDebug("Debug level enabled");
}
}
}

public static class Log
{
public static ILogger getLogger()
{
return LoggerSingleton.Instance.Logger;
Expand Down