diff --git a/Services/EmployeeRfidTagSyncService.cs b/Services/EmployeeRfidTagSyncService.cs index baac2d6..b498b06 100644 --- a/Services/EmployeeRfidTagSyncService.cs +++ b/Services/EmployeeRfidTagSyncService.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using MySqlConnector; using UtopiaCanteenSystem.Data; using UtopiaCanteenSystem.Models; +using UtopiaCanteenSystem.Services.Logging; namespace UtopiaCanteenSystem.Services; @@ -22,9 +23,12 @@ public class EmployeeRfidTagSyncService : IEmployeeRfidTagSyncService public async Task SyncAllAsync(CancellationToken cancellationToken = default) { + FileLogger.Info("CacheSync", "Employee RFID sync started."); + var connectionString = _configService.GetHrmsLookupConnectionString(); if (string.IsNullOrWhiteSpace(connectionString)) { + FileLogger.Warn("CacheSync", "Employee RFID sync skipped. MySQL connection string is not configured."); return new EmployeeRfidTagSyncResult { Success = false, @@ -36,10 +40,12 @@ public class EmployeeRfidTagSyncService : IEmployeeRfidTagSyncService try { rows = await FetchAllFromHrmsAsync(connectionString, cancellationToken).ConfigureAwait(false); + FileLogger.Info("CacheSync", $"Employee RFID rows fetched from HRMS/UIND. RowsFetched={rows.Count}."); } catch (Exception ex) { Logger.Log(ex, "EmployeeRfidTagSyncService.SyncAllAsync"); + FileLogger.Error("CacheSync", "Employee RFID sync failed while fetching from HRMS/UIND.", ex); return new EmployeeRfidTagSyncResult { Success = false, @@ -85,6 +91,10 @@ public class EmployeeRfidTagSyncService : IEmployeeRfidTagSyncService await db.SaveChangesAsync(cancellationToken).ConfigureAwait(false); _configService.SetLastEmployeeRfidCacheSyncUtc(syncedAt); + FileLogger.Info( + "CacheSync", + $"Employee RFID sync completed. RowsFetched={rows.Count}, Upserted={upserted}."); + return new EmployeeRfidTagSyncResult { Success = true, diff --git a/Services/MealMenuCacheSyncService.cs b/Services/MealMenuCacheSyncService.cs index 1ffc0b9..78240c7 100644 --- a/Services/MealMenuCacheSyncService.cs +++ b/Services/MealMenuCacheSyncService.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using MySqlConnector; using UtopiaCanteenSystem.Data; using UtopiaCanteenSystem.Models; +using UtopiaCanteenSystem.Services.Logging; namespace UtopiaCanteenSystem.Services; @@ -21,9 +22,12 @@ public class MealMenuCacheSyncService : IMealMenuCacheSyncService public async Task SyncAllAsync(CancellationToken cancellationToken = default) { + FileLogger.Info("CacheSync", "Meal/menu cache sync started."); + var connectionString = _configService.GetHrmsLookupConnectionString(); if (string.IsNullOrWhiteSpace(connectionString)) { + FileLogger.Warn("CacheSync", "Meal/menu sync skipped. MySQL connection string is not configured."); return new MealMenuCacheSyncResult { Success = false, @@ -49,6 +53,11 @@ public class MealMenuCacheSyncService : IMealMenuCacheSyncService await db.SaveChangesAsync(cancellationToken).ConfigureAwait(false); _configService.SetLastMealMenuCacheSyncUtc(syncedAt); + FileLogger.Info( + "CacheSync", + $"Meal/menu sync completed. MealSchedules={mealScheduleCount}, MenuWeeks={lunchWeekCount}, " + + $"MenuItems={lunchItemCount}, CatalogItems={menuItemCount}."); + return new MealMenuCacheSyncResult { Success = true, @@ -61,6 +70,7 @@ public class MealMenuCacheSyncService : IMealMenuCacheSyncService catch (Exception ex) { Logger.Log(ex, "MealMenuCacheSyncService.SyncAllAsync"); + FileLogger.Error("CacheSync", $"Meal/menu sync failed. Error={ex.Message}", ex); return new MealMenuCacheSyncResult { Success = false, diff --git a/Services/NavigationService.cs b/Services/NavigationService.cs index bdf1db1..8a5a5b1 100644 --- a/Services/NavigationService.cs +++ b/Services/NavigationService.cs @@ -1,5 +1,7 @@ using UtopiaCanteenSystem.ViewModels; +using UtopiaCanteenSystem.Services.Logging; + namespace UtopiaCanteenSystem.Services; /// @@ -105,6 +107,7 @@ public class NavigationService : INavigationService NavigateToAdminLogin(); return; } + FileLogger.Info("ClientNav", "Meal Schedules screen opened."); CurrentViewModel = _mealSchedulesVm(); } diff --git a/Services/OfflineCacheSyncService.cs b/Services/OfflineCacheSyncService.cs index 9347158..9103012 100644 --- a/Services/OfflineCacheSyncService.cs +++ b/Services/OfflineCacheSyncService.cs @@ -1,3 +1,5 @@ +using UtopiaCanteenSystem.Services.Logging; + namespace UtopiaCanteenSystem.Services; public class OfflineCacheSyncService : IOfflineCacheSyncService @@ -15,9 +17,12 @@ public class OfflineCacheSyncService : IOfflineCacheSyncService public async Task SyncEmployeeAndMenuCacheAsync(CancellationToken cancellationToken = default) { + FileLogger.Info("CacheSync", "Full offline cache sync started (employee RFID + meal/menu)."); + var employeeResult = await _employeeRfidTagSync.SyncAllAsync(cancellationToken).ConfigureAwait(false); if (!employeeResult.Success) { + FileLogger.Error("CacheSync", $"Full cache sync failed at employee RFID step. Error={employeeResult.ErrorMessage}"); return new OfflineCacheSyncResult { Success = false, @@ -29,6 +34,7 @@ public class OfflineCacheSyncService : IOfflineCacheSyncService var mealMenuResult = await _mealMenuCacheSync.SyncAllAsync(cancellationToken).ConfigureAwait(false); if (!mealMenuResult.Success) { + FileLogger.Error("CacheSync", $"Full cache sync failed at meal/menu step. Error={mealMenuResult.ErrorMessage}"); return new OfflineCacheSyncResult { Success = false, @@ -38,6 +44,8 @@ public class OfflineCacheSyncService : IOfflineCacheSyncService }; } + FileLogger.Info("CacheSync", "Full offline cache sync completed successfully."); + return new OfflineCacheSyncResult { Success = true,