From b8390162d90681da9dd2e728579ebb063bb946a6 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Mon, 6 Oct 2025 17:38:19 +0100 Subject: [PATCH] Add: Enhanced push notification logging for debugging --- LittleShop/Services/PushNotificationService.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/LittleShop/Services/PushNotificationService.cs b/LittleShop/Services/PushNotificationService.cs index 2bb2a3b..16030ca 100644 --- a/LittleShop/Services/PushNotificationService.cs +++ b/LittleShop/Services/PushNotificationService.cs @@ -274,7 +274,10 @@ public class PushNotificationService : IPushNotificationService private async Task SendNotificationToSubscriptions(List subscriptions, PushNotificationDto notification) { if (!subscriptions.Any()) + { + Log.Information("No active push subscriptions found for notification: {Title}", notification.Title); return false; + } int successCount = 0; var failedSubscriptions = new List(); @@ -289,6 +292,9 @@ public class PushNotificationService : IPushNotificationService data = notification.Data }); + Log.Information("Attempting to send push notification to {Count} subscriptions: {Title}", + subscriptions.Count, notification.Title); + foreach (var subscription in subscriptions) { try @@ -300,7 +306,7 @@ public class PushNotificationService : IPushNotificationService ); await _webPushClient.SendNotificationAsync(pushSubscription, payload, _vapidDetails); - + // Update last used time subscription.LastUsedAt = DateTime.UtcNow; successCount++; @@ -324,8 +330,8 @@ public class PushNotificationService : IPushNotificationService // Save changes to update last used times and inactive subscriptions await _context.SaveChangesAsync(); - Log.Information("Push notifications sent: {SuccessCount} successful, {FailedCount} failed", - successCount, failedSubscriptions.Count); + Log.Information("Push notifications sent: {SuccessCount} successful, {FailedCount} failed (Total subscriptions: {Total})", + successCount, failedSubscriptions.Count, subscriptions.Count); return successCount > 0; }