|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -#nullable disable warnings |
5 |
| - |
6 |
| -using System; |
7 | 4 | using Microsoft.AspNetCore.Components.Rendering;
|
8 | 5 | using Microsoft.Extensions.Logging;
|
9 | 6 |
|
10 | 7 | namespace Microsoft.AspNetCore.Components.RenderTree
|
11 | 8 | {
|
12 | 9 | public abstract partial class Renderer
|
13 | 10 | {
|
14 |
| - internal static class Log |
| 11 | + internal static partial class Log |
15 | 12 | {
|
16 |
| - private static readonly LogDefineOptions SkipEnabledCheckLogOptions = new() { SkipEnabledCheck = true }; |
17 |
| - |
18 |
| - private static readonly Action<ILogger, int, Type, int, Type, Exception> _initializingChildComponent = |
19 |
| - LoggerMessage.Define<int, Type, int, Type>(LogLevel.Debug, new EventId(1, "InitializingChildComponent"), "Initializing component {ComponentId} ({ComponentType}) as child of {ParentComponentId} ({ParentComponentId})", SkipEnabledCheckLogOptions); |
20 |
| - |
21 |
| - private static readonly Action<ILogger, int, Type, Exception> _initializingRootComponent = |
22 |
| - LoggerMessage.Define<int, Type>(LogLevel.Debug, new EventId(2, "InitializingRootComponent"), "Initializing root component {ComponentId} ({ComponentType})", SkipEnabledCheckLogOptions); |
| 13 | + [LoggerMessage(1, LogLevel.Debug, "Initializing component {ComponentId} ({ComponentType}) as child of {ParentComponentId} ({ParentComponentType})", EventName = "InitializingChildComponent", SkipEnabledCheck = true)] |
| 14 | + private static partial void InitializingChildComponent(ILogger logger, int componentId, Type componentType, int parentComponentId, Type parentComponentType); |
23 | 15 |
|
24 |
| - private static readonly Action<ILogger, int, Type, Exception> _renderingComponent = |
25 |
| - LoggerMessage.Define<int, Type>(LogLevel.Debug, new EventId(3, "RenderingComponent"), "Rendering component {ComponentId} of type {ComponentType}", SkipEnabledCheckLogOptions); |
26 |
| - |
27 |
| - private static readonly Action<ILogger, int, Type, Exception> _disposingComponent = |
28 |
| - LoggerMessage.Define<int, Type>(LogLevel.Debug, new EventId(4, "DisposingComponent"), "Disposing component {ComponentId} of type {ComponentType}", SkipEnabledCheckLogOptions); |
29 |
| - |
30 |
| - private static readonly Action<ILogger, ulong, string, Exception> _handlingEvent = |
31 |
| - LoggerMessage.Define<ulong, string>(LogLevel.Debug, new EventId(5, "HandlingEvent"), "Handling event {EventId} of type '{EventType}'"); |
| 16 | + [LoggerMessage(2, LogLevel.Debug, "Initializing root component {ComponentId} ({ComponentType})", EventName = "InitializingRootComponent", SkipEnabledCheck = true)] |
| 17 | + private static partial void InitializingRootComponent(ILogger logger, int componentId, Type componentType); |
32 | 18 |
|
33 | 19 | public static void InitializingComponent(ILogger logger, ComponentState componentState, ComponentState parentComponentState)
|
34 | 20 | {
|
35 | 21 | if (logger.IsEnabled(LogLevel.Debug)) // This is almost always false, so skip the evaluations
|
36 | 22 | {
|
37 | 23 | if (parentComponentState == null)
|
38 | 24 | {
|
39 |
| - _initializingRootComponent(logger, componentState.ComponentId, componentState.Component.GetType(), null); |
| 25 | + InitializingRootComponent(logger, componentState.ComponentId, componentState.Component.GetType()); |
40 | 26 | }
|
41 | 27 | else
|
42 | 28 | {
|
43 |
| - _initializingChildComponent(logger, componentState.ComponentId, componentState.Component.GetType(), parentComponentState.ComponentId, parentComponentState.Component.GetType(), null); |
| 29 | + InitializingChildComponent(logger, componentState.ComponentId, componentState.Component.GetType(), parentComponentState.ComponentId, parentComponentState.Component.GetType()); |
44 | 30 | }
|
45 | 31 | }
|
46 | 32 | }
|
47 | 33 |
|
| 34 | + [LoggerMessage(3, LogLevel.Debug, "Rendering component {ComponentId} of type {ComponentType}", EventName = "RenderingComponent", SkipEnabledCheck = true)] |
| 35 | + private static partial void RenderingComponent(ILogger logger, int componentId, Type componentType); |
| 36 | + |
48 | 37 | public static void RenderingComponent(ILogger logger, ComponentState componentState)
|
49 | 38 | {
|
50 | 39 | if (logger.IsEnabled(LogLevel.Debug)) // This is almost always false, so skip the evaluations
|
51 | 40 | {
|
52 |
| - _renderingComponent(logger, componentState.ComponentId, componentState.Component.GetType(), null); |
| 41 | + RenderingComponent(logger, componentState.ComponentId, componentState.Component.GetType()); |
53 | 42 | }
|
54 | 43 | }
|
55 | 44 |
|
| 45 | + [LoggerMessage(4, LogLevel.Debug, "Disposing component {ComponentId} of type {ComponentType}", EventName = "DisposingComponent", SkipEnabledCheck = true)] |
| 46 | + private static partial void DisposingComponent(ILogger<Renderer> logger, int componentId, Type componentType); |
| 47 | + |
56 | 48 | public static void DisposingComponent(ILogger<Renderer> logger, ComponentState componentState)
|
57 | 49 | {
|
58 | 50 | if (logger.IsEnabled(LogLevel.Debug)) // This is almost always false, so skip the evaluations
|
59 | 51 | {
|
60 |
| - _disposingComponent(logger, componentState.ComponentId, componentState.Component.GetType(), null); |
| 52 | + DisposingComponent(logger, componentState.ComponentId, componentState.Component.GetType()); |
61 | 53 | }
|
62 | 54 | }
|
63 | 55 |
|
64 |
| - public static void HandlingEvent(ILogger<Renderer> logger, ulong eventHandlerId, EventArgs eventArgs) |
| 56 | + [LoggerMessage(5, LogLevel.Debug, "Handling event {EventId} of type '{EventType}'", EventName = "HandlingEvent", SkipEnabledCheck = true)] |
| 57 | + public static partial void HandlingEvent(ILogger<Renderer> logger, ulong eventId, string eventType); |
| 58 | + |
| 59 | + public static void HandlingEvent(ILogger<Renderer> logger, ulong eventHandlerId, EventArgs? eventArgs) |
65 | 60 | {
|
66 |
| - _handlingEvent(logger, eventHandlerId, eventArgs?.GetType().Name ?? "null", null); |
| 61 | + if (logger.IsEnabled(LogLevel.Debug)) // This is almost always false, so skip the evaluations |
| 62 | + { |
| 63 | + HandlingEvent(logger, eventHandlerId, eventArgs?.GetType().Name ?? "null"); |
| 64 | + } |
67 | 65 | }
|
68 | 66 | }
|
69 | 67 | }
|
|
0 commit comments