< Summary

Information
Class: NanoRoute.Internals.RouterEventSource
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RouterEventSource.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 73
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
RouterEventSource()20
RouterEventSource()100

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RouterEventSource.cs

#LineLine coverage
 1/********************************************************************************
 2* RouterEventSource.cs                                                          *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Diagnostics.CodeAnalysis;
 8using System.Diagnostics.Tracing;
 9
 10namespace NanoRoute.Internals
 11{
 12    /// <summary>
 13    /// Exposes events from this library.
 14    /// </summary>
 15    /// <remarks>This logger is not meant to log user errors.</remarks>
 16    [EventSource(Name = EVENT_SOURCE_NAME)]
 17    internal sealed class RouterEventSource : EventSource
 18    {
 219        private RouterEventSource()
 220        {
 221        }
 22
 23        /// <summary>
 24        /// The name associated with the event source declaration.
 25        /// </summary>
 26        public const string EVENT_SOURCE_NAME = "NanoRoute";
 27
 28        /// <summary>
 29        /// The singleton instance.
 30        /// </summary>
 231        public static RouterEventSource Instance { get; } = new();
 32
 233        public static EventSourceWriter Debug { get; } = new EventSourceWriter(Instance, EventLevel.Verbose);
 34
 235        public static EventSourceWriter Info { get; } = new EventSourceWriter(Instance, EventLevel.Informational);
 36
 237        public static EventSourceWriter Warning { get; } = new EventSourceWriter(Instance, EventLevel.Warning);
 38
 239        public static EventSourceWriter Error { get; } = new EventSourceWriter(Instance, EventLevel.Error);
 40    }
 41
 42    /// <summary>
 43    /// Defines some extensions methods over the <see cref="EventSource"/> class.
 44    /// </summary>
 45    internal sealed class EventSourceWriter(EventSource target, EventLevel level)
 46    {
 47        private readonly EventSourceOptions _options = new() { Level = level };
 48
 49        /// <summary>
 50        /// Logs a message with the given <see cref="Level"/>. The <paramref name="attributesFactory"/> is called only w
 51        /// </summary>
 52        [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The 'attributesFactory' won't return compos
 53        public void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T, TParam>(strin
 54        {
 55            if (target.IsEnabled(Level, EventKeywords.None))
 56                target.Write(eventName, _options, attributesFactory(p));
 57        }
 58
 59        /// <summary>
 60        /// Logs a message with the given <see cref="Level"/>. The <paramref name="attributesFactory"/> is called only w
 61        /// </summary>
 62        [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The 'attributesFactory' won't return compos
 63        public void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T, TParam_1, TPa
 64        {
 65            if (target.IsEnabled(Level, EventKeywords.None))
 66                target.Write(eventName, _options, attributesFactory(p1, p2));
 67        }
 68
 69        public EventLevel Level { get; } = level;
 70
 71        public override string ToString() => Level.ToString();
 72    }
 73}