< Summary - SonghayCore

Information
Class: Songhay.Diagnostics.TraceSources
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Diagnostics/TraceSources.cs
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 84
Line coverage: 94.4%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_ConfiguredTraceSourceName()100%1100%
set_ConfiguredTraceSourceName(...)100%1100%
get_IsConfiguredTraceSourceNameLoaded()100%1100%
.ctor()100%1100%
GetTraceSourceFromConfiguredName()100%1100%
GetTraceSource(...)100%4100%
get_Item(...)100%10%
get_Instance()100%1100%
.cctor()100%1100%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Diagnostics/TraceSources.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2
 3namespace Songhay.Diagnostics;
 4
 5/// <summary>
 6/// Singleton wrapper for <see cref="TraceSource"/>
 7/// </summary>
 8/// <remarks>
 9/// Based on Fonlow.Diagnostics by Zijian Huang [https://github.com/zijianhuang/Fonlow.Diagnostics]
 10/// Also see “Use TraceSource Efficiently” [http://www.codeproject.com/Tips/1071853/Use-TraceSource-Efficiently]
 11/// </remarks>
 12public class TraceSources
 13{
 14    /// <summary>
 15    /// The conventional <see cref="TraceSource"/> name.
 16    /// </summary>
 17    public const string DefaultTraceSourceName = "rx-trace";
 18
 19    /// <summary>
 20    /// The configured trace source name
 21    /// </summary>
 22    public static string? ConfiguredTraceSourceName
 23    {
 1424        get => _configuredTraceSourceName;
 25        set
 926        {
 927            _configuredTraceSourceName = value;
 928            IsConfiguredTraceSourceNameLoaded = true;
 929        }
 30    }
 31
 32    /// <summary>
 33    /// The is configured trace source name loaded?
 34    /// </summary>
 1135    public static bool IsConfiguredTraceSourceNameLoaded { get; private set; }
 36
 37    /// <summary>
 38    /// Prevents a default instance of the <see cref="TraceSources"/> class from being created.
 39    /// </summary>
 240    TraceSources() => _traceSources = new ConcurrentDictionary<string, TraceSource>();
 41
 42    /// <summary>
 43    /// Gets the name of the trace source from configuration.
 44    /// </summary>
 45    /// <remarks>
 46    /// When the trace source name is not configured
 47    /// then <see cref="DefaultTraceSourceName"/> is used.
 48    /// </remarks>
 1449    public TraceSource? GetTraceSourceFromConfiguredName() => GetTraceSource(ConfiguredTraceSourceName);
 50
 51    /// <summary>
 52    /// Gets the trace source.
 53    /// </summary>
 54    /// <param name="name">The name.</param>
 55    public TraceSource? GetTraceSource(string? name)
 1456    {
 1657        if (string.IsNullOrWhiteSpace(name)) return null;
 2258        if (_traceSources.TryGetValue(name, out TraceSource? r)) return r;
 59
 260        r = new TraceSource(name);
 261        _traceSources.TryAdd(name, r);
 262        return r;
 1463    }
 64
 65    /// <summary>
 66    /// Gets the <see cref="TraceSource"/> with the specified name.
 67    /// </summary>
 68    /// <param name="name">The name.</param>
 069    public TraceSource? this[string? name] => GetTraceSource(name);
 70
 71    /// <summary>
 72    /// Gets the instance.
 73    /// </summary>
 1474    public static TraceSources Instance => Nested.NestedInstance;
 75
 76    readonly ConcurrentDictionary<string, TraceSource> _traceSources;
 77
 78    static class Nested
 79    {
 180        internal static readonly TraceSources NestedInstance = new();
 81    }
 82
 83    static string? _configuredTraceSourceName;
 84}