< Summary

Information
Class: ArturRios.Logging.StandaloneLogger
Assembly: ArturRios.Logging
File(s): D:\Repositories\dotnet-logging\src\StandaloneLogger.cs
Line coverage
95%
Covered lines: 57
Uncovered lines: 3
Coverable lines: 60
Total lines: 157
Line coverage: 95%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage
100%
Covered methods: 11
Fully covered methods: 10
Total methods: 11
Method coverage: 100%
Full method coverage: 90.9%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%2262.5%
get_TraceId()100%11100%
Trace(...)100%22100%
Debug(...)100%22100%
Info(...)100%22100%
Warn(...)100%22100%
Error(...)100%22100%
Exception(...)100%22100%
Critical(...)100%22100%
Fatal(...)100%22100%
FormatMessageWithTraceId(...)100%22100%

File(s)

D:\Repositories\dotnet-logging\src\StandaloneLogger.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using ArturRios.Logging.Configuration;
 3using ArturRios.Logging.Factories;
 4using ArturRios.Logging.Interfaces;
 5
 6namespace ArturRios.Logging;
 7
 8/// <summary>
 9/// A standalone logger that automatically captures caller information using compiler attributes.
 10/// Supports multiple logger configurations and optional trace ID tracking.
 11/// </summary>
 12public class StandaloneLogger : IStandaloneLogger
 13{
 1814    private readonly List<IInternalLogger> _loggers = [];
 15
 16    /// <summary>
 17    /// Gets or sets the trace ID for correlating log entries across related operations.
 18    /// </summary>
 3519    public string? TraceId { get; set; }
 20
 21    /// <summary>
 22    /// Initializes a new instance of the <see cref="StandaloneLogger"/> class with the specified configurations.
 23    /// </summary>
 24    /// <param name="configurations">The list of logger configurations to use.</param>
 1825    public StandaloneLogger(List<LoggerConfiguration> configurations)
 1826    {
 5427        foreach (var config in configurations)
 028        {
 029            _loggers.Add(InternalLoggerFactory.Create(config));
 030        }
 1831    }
 32
 33    /// <summary>
 34    /// Logs a trace-level message with automatic caller information capture.
 35    /// </summary>
 36    /// <param name="message">The message to log.</param>
 37    /// <param name="filePath">The source file path (automatically captured).</param>
 38    /// <param name="methodName">The calling method name (automatically captured).</param>
 39    public void Trace(string message, [CallerFilePath] string filePath = "unknown",
 40        [CallerMemberName] string methodName = "unknown")
 441    {
 2042        foreach (var logger in _loggers)
 443        {
 444            logger.Trace(FormatMessageWithTraceId(message), filePath, methodName);
 445        }
 446    }
 47
 48    /// <summary>
 49    /// Logs a debug-level message with automatic caller information capture.
 50    /// </summary>
 51    /// <param name="message">The message to log.</param>
 52    /// <param name="filePath">The source file path (automatically captured).</param>
 53    /// <param name="methodName">The calling method name (automatically captured).</param>
 54    public void Debug(string message, [CallerFilePath] string filePath = "unknown",
 55        [CallerMemberName] string methodName = "unknown")
 256    {
 1057        foreach (var logger in _loggers)
 258        {
 259            logger.Debug(FormatMessageWithTraceId(message), filePath, methodName);
 260        }
 261    }
 62
 63    /// <summary>
 64    /// Logs an information-level message with automatic caller information capture.
 65    /// </summary>
 66    /// <param name="message">The message to log.</param>
 67    /// <param name="filePath">The source file path (automatically captured).</param>
 68    /// <param name="methodName">The calling method name (automatically captured).</param>
 69    public void Info(string message, [CallerFilePath] string filePath = "unknown",
 70        [CallerMemberName] string methodName = "unknown")
 271    {
 1272        foreach (var logger in _loggers)
 373        {
 374            logger.Info(FormatMessageWithTraceId(message), filePath, methodName);
 375        }
 276    }
 77
 78    /// <summary>
 79    /// Logs a warning-level message with automatic caller information capture.
 80    /// </summary>
 81    /// <param name="message">The message to log.</param>
 82    /// <param name="filePath">The source file path (automatically captured).</param>
 83    /// <param name="methodName">The calling method name (automatically captured).</param>
 84    public void Warn(string message, [CallerFilePath] string filePath = "unknown",
 85        [CallerMemberName] string methodName = "unknown")
 286    {
 1087        foreach (var logger in _loggers)
 288        {
 289            logger.Warn(FormatMessageWithTraceId(message), filePath, methodName);
 290        }
 291    }
 92
 93    /// <summary>
 94    /// Logs an error-level message with automatic caller information capture.
 95    /// </summary>
 96    /// <param name="message">The message to log.</param>
 97    /// <param name="filePath">The source file path (automatically captured).</param>
 98    /// <param name="methodName">The calling method name (automatically captured).</param>
 99    public void Error(string message, [CallerFilePath] string filePath = "unknown",
 100        [CallerMemberName] string methodName = "unknown")
 2101    {
 10102        foreach (var logger in _loggers)
 2103        {
 2104            logger.Error(FormatMessageWithTraceId(message), filePath, methodName);
 2105        }
 2106    }
 107
 108    /// <summary>
 109    /// Logs an exception with automatic caller information capture.
 110    /// </summary>
 111    /// <param name="exception">The exception to log.</param>
 112    /// <param name="filePath">The source file path (automatically captured).</param>
 113    /// <param name="methodName">The calling method name (automatically captured).</param>
 114    public void Exception(Exception exception, [CallerFilePath] string filePath = "unknown",
 115        [CallerMemberName] string methodName = "unknown")
 2116    {
 10117        foreach (var logger in _loggers)
 2118        {
 2119            logger.Exception(FormatMessageWithTraceId(exception.Message), filePath, methodName);
 2120        }
 2121    }
 122
 123    /// <summary>
 124    /// Logs a critical-level message with automatic caller information capture.
 125    /// </summary>
 126    /// <param name="message">The message to log.</param>
 127    /// <param name="filePath">The source file path (automatically captured).</param>
 128    /// <param name="methodName">The calling method name (automatically captured).</param>
 129    public void Critical(string message, [CallerFilePath] string filePath = "unknown",
 130        [CallerMemberName] string methodName = "unknown")
 2131    {
 10132        foreach (var logger in _loggers)
 2133        {
 2134            logger.Critical(FormatMessageWithTraceId(message), filePath, methodName);
 2135        }
 2136    }
 137
 138    /// <summary>
 139    /// Logs a fatal-level message with automatic caller information capture.
 140    /// </summary>
 141    /// <param name="message">The message to log.</param>
 142    /// <param name="filePath">The source file path (automatically captured).</param>
 143    /// <param name="methodName">The calling method name (automatically captured).</param>
 144    public void Fatal(string message, [CallerFilePath] string filePath = "unknown",
 145        [CallerMemberName] string methodName = "unknown")
 2146    {
 10147        foreach (var logger in _loggers)
 2148        {
 2149            logger.Fatal(FormatMessageWithTraceId(message), filePath, methodName);
 2150        }
 2151    }
 152
 153    private string FormatMessageWithTraceId(string message)
 19154    {
 19155        return !string.IsNullOrEmpty(TraceId) ? $"[{nameof(TraceId)}] {TraceId} | {message}" : message;
 19156    }
 157}