< Summary

Information
Class: NanoRoute.Internals.EventSourceWriter
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RouterEventSource.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
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

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    {
 19        private RouterEventSource()
 20        {
 21        }
 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>
 31        public static RouterEventSource Instance { get; } = new();
 32
 33        public static EventSourceWriter Debug { get; } = new EventSourceWriter(Instance, EventLevel.Verbose);
 34
 35        public static EventSourceWriter Info { get; } = new EventSourceWriter(Instance, EventLevel.Informational);
 36
 37        public static EventSourceWriter Warning { get; } = new EventSourceWriter(Instance, EventLevel.Warning);
 38
 39        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>
 245    internal sealed class EventSourceWriter(EventSource target, EventLevel level)
 46    {
 247        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
 254        {
 255            if (target.IsEnabled(Level, EventKeywords.None))
 156                target.Write(eventName, _options, attributesFactory(p));
 257        }
 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
 264        {
 265            if (target.IsEnabled(Level, EventKeywords.None))
 166                target.Write(eventName, _options, attributesFactory(p1, p2));
 267        }
 68
 269        public EventLevel Level { get; } = level;
 70
 171        public override string ToString() => Level.ToString();
 72    }
 73}