Add: Enhanced push notification logging for debugging

This commit is contained in:
SysAdmin 2025-10-06 17:38:19 +01:00
parent b265c89a72
commit b8390162d9

View File

@ -274,7 +274,10 @@ public class PushNotificationService : IPushNotificationService
private async Task<bool> SendNotificationToSubscriptions(List<Models.PushSubscription> 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<Models.PushSubscription>();
@ -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;
}