From 1718de3536308e65dd6acc7ab575f3a17828faed Mon Sep 17 00:00:00 2001 From: Liam Morrow Date: Mon, 13 Jan 2025 17:22:40 +1100 Subject: [PATCH] Add logger for each action so we can trace breadcrumbs --- LiftLog.Ui/ServiceRegistration.cs | 2 ++ LiftLog.Ui/Store/LogActionMiddleware.cs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 LiftLog.Ui/Store/LogActionMiddleware.cs diff --git a/LiftLog.Ui/ServiceRegistration.cs b/LiftLog.Ui/ServiceRegistration.cs index 3c3868c9..eb28d578 100644 --- a/LiftLog.Ui/ServiceRegistration.cs +++ b/LiftLog.Ui/ServiceRegistration.cs @@ -4,6 +4,7 @@ using LiftLog.Lib.Serialization; using LiftLog.Lib.Services; using LiftLog.Ui.Services; +using LiftLog.Ui.Store; using LiftLog.Ui.Store.App; using LiftLog.Ui.Store.CurrentSession; using LiftLog.Ui.Store.Feed; @@ -58,6 +59,7 @@ public static IServiceCollection RegisterUiServices< .AddMiddleware() .AddMiddleware() .AddMiddleware() + .AddMiddleware() #if DEBUG // .UseReduxDevTools() // Fails to load #endif diff --git a/LiftLog.Ui/Store/LogActionMiddleware.cs b/LiftLog.Ui/Store/LogActionMiddleware.cs new file mode 100644 index 00000000..3c4f96df --- /dev/null +++ b/LiftLog.Ui/Store/LogActionMiddleware.cs @@ -0,0 +1,22 @@ +using System.Diagnostics; +using Fluxor; +using LiftLog.Ui.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Logging; + +namespace LiftLog.Ui.Store; + +public class LogActionMiddleware(ILogger logger) : Middleware +{ + public override void BeforeDispatch(object action) + { + logger.LogInformation("Dispatching action {Action}", action?.GetType()); + base.BeforeDispatch(action); + } + + public override void AfterDispatch(object action) + { + logger.LogInformation("Action {Action} dispatched", action?.GetType()); + base.AfterDispatch(action); + } +}