Skip to content

Commit

Permalink
Add logger for each action so we can trace breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Jan 13, 2025
1 parent 6557e64 commit 1718de3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions LiftLog.Ui/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static IServiceCollection RegisterUiServices<
.AddMiddleware<AppStateInitMiddleware>()
.AddMiddleware<SettingsStateInitMiddleware>()
.AddMiddleware<FeedStateInitMiddleware>()
.AddMiddleware<LogActionMiddleware>()
#if DEBUG
// .UseReduxDevTools() // Fails to load
#endif
Expand Down
22 changes: 22 additions & 0 deletions LiftLog.Ui/Store/LogActionMiddleware.cs
Original file line number Diff line number Diff line change
@@ -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<LogActionMiddleware> 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);
}
}

0 comments on commit 1718de3

Please sign in to comment.