< Summary

Information
Class: ArturRios.Logging.Loggers.ConsoleLogger
Assembly: ArturRios.Logging
File(s): D:\Repositories\dotnet-logging\src\Loggers\ConsoleLogger.cs
Line coverage
86%
Covered lines: 46
Uncovered lines: 7
Coverable lines: 53
Total lines: 97
Line coverage: 86.7%
Branch coverage
27%
Covered branches: 3
Total branches: 11
Branch coverage: 27.2%
Method coverage
100%
Covered methods: 12
Fully covered methods: 10
Total methods: 12
Method coverage: 100%
Full method coverage: 83.3%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
Trace(...)100%11100%
Debug(...)100%11100%
Info(...)100%11100%
Warn(...)100%11100%
Error(...)100%11100%
Exception(...)100%11100%
Critical(...)100%11100%
Fatal(...)100%11100%
GetAnsiColorSequence(...)11.11%30936.36%
Write(...)100%22100%

File(s)

D:\Repositories\dotnet-logging\src\Loggers\ConsoleLogger.cs

#LineLine coverage
 1using ArturRios.Logging.Configuration;
 2using ArturRios.Logging.Factories;
 3using ArturRios.Logging.Interfaces;
 4using ArturRios.Util.Collections;
 5
 6namespace ArturRios.Logging.Loggers;
 7
 298public class ConsoleLogger(ConsoleLoggerConfiguration configuration) : IInternalLogger
 9{
 110    private static readonly Lock s_writeLock = new();
 11
 12    /// <inheritdoc />
 13    public void Trace(string message, string filePath, string methodName)
 314    {
 315        Write(CustomLogLevel.Trace, filePath, methodName, message);
 316    }
 17
 18    /// <inheritdoc />
 19    public void Debug(string message, string filePath, string methodName)
 320    {
 321        Write(CustomLogLevel.Debug, filePath, methodName, message);
 322    }
 23
 24    /// <inheritdoc />
 25    public void Info(string message, string filePath, string methodName)
 2026    {
 2027        Write(CustomLogLevel.Information, filePath, methodName, message);
 2028    }
 29
 30    /// <inheritdoc />
 31    public void Warn(string message, string filePath, string methodName)
 232    {
 233        Write(CustomLogLevel.Warning, filePath, methodName, message);
 234    }
 35
 36    /// <inheritdoc />
 37    public void Error(string message, string filePath, string methodName)
 338    {
 339        Write(CustomLogLevel.Error, filePath, methodName, message);
 340    }
 41
 42    /// <inheritdoc />
 43    public void Exception(string message, string filePath, string methodName)
 244    {
 245        Write(CustomLogLevel.Exception, filePath, methodName, message);
 246    }
 47
 48    /// <inheritdoc />
 49    public void Critical(string message, string filePath, string methodName)
 250    {
 251        Write(CustomLogLevel.Critical, filePath, methodName, message);
 252    }
 53
 54    /// <inheritdoc />
 55    public void Fatal(string message, string filePath, string methodName)
 256    {
 257        Write(CustomLogLevel.Fatal, filePath, methodName, message);
 258    }
 59
 160    private static string GetAnsiColorSequence(CustomLogLevel level) => level switch
 161    {
 062        CustomLogLevel.Trace => AnsiColors.DarkGray,
 063        CustomLogLevel.Debug => AnsiColors.Cyan,
 164        CustomLogLevel.Information => AnsiColors.Green,
 065        CustomLogLevel.Warning => AnsiColors.Yellow,
 066        CustomLogLevel.Error => AnsiColors.Red,
 067        CustomLogLevel.Exception => AnsiColors.Magenta,
 068        CustomLogLevel.Critical or CustomLogLevel.Fatal => AnsiColors.BrightRed,
 069        _ => AnsiColors.White
 170    };
 71
 72    private void Write(CustomLogLevel level, string filePath, string methodName, string message)
 3773    {
 3774        var entry = LogEntryFactory.Create(level, filePath, methodName, message);
 75
 3776        if (configuration.UseColors)
 177        {
 178            _ = ConsoleAnsi.EnableVirtualTerminalProcessing();
 79
 180            var ansiColor = GetAnsiColorSequence(level);
 81
 82            const string colorReset = "\e[0m";
 83
 84            lock (s_writeLock)
 185            {
 186                Console.Write(ansiColor + entry + colorReset);
 187            }
 188        }
 89        else
 3690        {
 91            lock (s_writeLock)
 3692            {
 3693                Console.Write(entry);
 3694            }
 3695        }
 3796    }
 97}