diff --git a/common/services/ASC.Data.Backup.BackgroundTasks/GlobalUsings.cs b/common/services/ASC.Data.Backup.BackgroundTasks/GlobalUsings.cs index 9b5c1a98a1..fe5d39f17c 100644 --- a/common/services/ASC.Data.Backup.BackgroundTasks/GlobalUsings.cs +++ b/common/services/ASC.Data.Backup.BackgroundTasks/GlobalUsings.cs @@ -30,16 +30,18 @@ global using ASC.Common; global using ASC.Common.Caching; global using ASC.Common.Utils; global using ASC.Core; -global using ASC.Core.Billing; +global using ASC.Core.Billing; global using ASC.Core.Common.Hosting; global using ASC.Core.Common.Hosting.Interfaces; global using ASC.Data.Backup.BackgroundTasks; +global using ASC.Data.Backup.BackgroundTasks.Log; global using ASC.Data.Backup.Contracts; global using ASC.Data.Backup.Core.IntegrationEvents.Events; global using ASC.Data.Backup.IntegrationEvents.EventHandling; global using ASC.Data.Backup.Services; global using ASC.Data.Backup.Storage; global using ASC.EventBus.Abstractions; +global using ASC.EventBus.Events; global using ASC.Files.Core; global using ASC.Web.Studio.Core.Notify; diff --git a/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupDeleteScheldureRequestIntegrationEventHandler.cs b/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupDeleteScheldureRequestIntegrationEventHandler.cs index 7fb62d6c01..3c739b8579 100644 --- a/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupDeleteScheldureRequestIntegrationEventHandler.cs +++ b/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupDeleteScheldureRequestIntegrationEventHandler.cs @@ -44,7 +44,7 @@ public class BackupDeleteScheldureRequestIntegrationEventHandler : IIntegrationE public async Task Handle(IntegrationEvent @event) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); + _logger.InformationHandlingIntegrationEvent(@event.Id, Program.AppName, @event); _backupService.DeleteSchedule(@event.TenantId); diff --git a/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupRequestIntegrationEventHandler.cs b/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupRequestIntegrationEventHandler.cs index 598ec01d20..ffdf608f82 100644 --- a/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupRequestIntegrationEventHandler.cs +++ b/common/services/ASC.Data.Backup.BackgroundTasks/IntegrationEvents/EventHandling/BackupRequestIntegrationEventHandler.cs @@ -56,7 +56,7 @@ public class BackupRequestIntegrationEventHandler : IIntegrationEventHandler _logger.LogDebug("#1 BackupCleanerService background task is stopping.")); + stoppingToken.Register(() => _logger.DebugBackupCleanerServiceStopping()); while (!stoppingToken.IsCancellationRequested) { - _logger.LogDebug("BackupCleanerService background task is doing background work."); + _logger.DebugBackupCleanerServiceDoingWork(); using var serviceScope = _scopeFactory.CreateScope(); @@ -59,7 +59,7 @@ internal sealed class BackupCleanerService : BackgroundService if (!await registerInstanceService.IsActive(RegisterInstanceWorkerService.InstanceId)) { - _logger.LogDebug($"BackupCleanerService background task with instance id {RegisterInstanceWorkerService.InstanceId} is't active."); + _logger.DebugBackupCleanerServiceIsNotActive(RegisterInstanceWorkerService.InstanceId); await Task.Delay(1000, stoppingToken); @@ -71,7 +71,7 @@ internal sealed class BackupCleanerService : BackgroundService await Task.Delay(_backupCleanerPeriod, stoppingToken); } - _logger.LogDebug("BackupCleanerService background task is stopping."); + _logger.DebugBackupCleanerServiceStopping(); } private void ExecuteBackupCleaner(CancellationToken stoppingToken) @@ -81,11 +81,11 @@ internal sealed class BackupCleanerService : BackgroundService var backupRepository = serviceScope.ServiceProvider.GetRequiredService(); var backupStorageFactory = serviceScope.ServiceProvider.GetRequiredService(); - _logger.LogDebug("started to clean expired backups"); + _logger.DebugStartedClean(); var backupsToRemove = backupRepository.GetExpiredBackupRecords(); - _logger.LogDebug("found {count} backups which are expired", backupsToRemove.Count); + _logger.DebugFoundBackups(backupsToRemove.Count); foreach (var scheduledBackups in backupRepository.GetScheduledBackupRecords().GroupBy(r => r.TenantId)) { @@ -101,7 +101,7 @@ internal sealed class BackupCleanerService : BackgroundService var scheduledBackupsToRemove = scheduledBackups.OrderByDescending(r => r.CreatedOn).Skip(schedule.BackupsStored).ToList(); if (scheduledBackupsToRemove.Any()) { - _logger.LogDebug("only last {storedCount} scheduled backup records are to keep for tenant {tenantId} so {removeCount} records must be removed", schedule.BackupsStored, schedule.TenantId, scheduledBackupsToRemove.Count); + _logger.DebugOnlyLast(schedule.BackupsStored, schedule.TenantId, scheduledBackupsToRemove.Count); backupsToRemove.AddRange(scheduledBackupsToRemove); } } @@ -132,7 +132,7 @@ internal sealed class BackupCleanerService : BackgroundService } catch (ProviderInfoArgumentException error) { - _logger.LogWarning(error, "can't remove backup record " + backupRecord.Id); + _logger.WarningCanNotRemoveBackup(backupRecord.Id, error); if (DateTime.UtcNow > backupRecord.CreatedOn.AddMonths(6)) { @@ -141,7 +141,7 @@ internal sealed class BackupCleanerService : BackgroundService } catch (Exception error) { - _logger.LogWarning(error, "can't remove backup record: " + backupRecord.Id); + _logger.WarningCanNotRemoveBackup(backupRecord.Id, error); } } diff --git a/common/services/ASC.Data.Backup.BackgroundTasks/Services/BackupSchedulerService.cs b/common/services/ASC.Data.Backup.BackgroundTasks/Services/BackupSchedulerService.cs index b8fc9da917..7eb02d7830 100644 --- a/common/services/ASC.Data.Backup.BackgroundTasks/Services/BackupSchedulerService.cs +++ b/common/services/ASC.Data.Backup.BackgroundTasks/Services/BackupSchedulerService.cs @@ -52,9 +52,9 @@ public sealed class BackupSchedulerService : BackgroundService protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - _logger.LogDebug("BackupSchedulerService is starting."); + _logger.DebugBackupSchedulerServiceStarting(); - stoppingToken.Register(() => _logger.LogDebug("#1 BackupSchedulerService background task is stopping.")); + stoppingToken.Register(() => _logger.DebugBackupSchedulerServiceStopping()); while (!stoppingToken.IsCancellationRequested) { @@ -64,21 +64,21 @@ public sealed class BackupSchedulerService : BackgroundService if (!await registerInstanceService.IsActive(RegisterInstanceWorkerService.InstanceId)) { - _logger.LogDebug($"BackupSchedulerService background task with instance id {RegisterInstanceWorkerService.InstanceId} is't active."); + _logger.DebugBackupSchedulerServiceIsNotActive(RegisterInstanceWorkerService.InstanceId); await Task.Delay(1000, stoppingToken); continue; } - _logger.LogDebug("BackupSchedulerService background task is doing background work."); + _logger.DebugBackupSchedulerServiceDoingWork(); ExecuteBackupScheduler(stoppingToken); await Task.Delay(_backupSchedulerPeriod, stoppingToken); } - _logger.LogDebug("BackupSchedulerService background task is stopping."); + _logger.DebugBackupSchedulerServiceStopping(); } private void ExecuteBackupScheduler(CancellationToken stoppingToken) @@ -90,11 +90,11 @@ public sealed class BackupSchedulerService : BackgroundService var backupSchedule = serviceScope.ServiceProvider.GetRequiredService(); var tenantManager = serviceScope.ServiceProvider.GetRequiredService(); - _logger.LogDebug("started to schedule backups"); + _logger.DebugStartedToSchedule(); var backupsToSchedule = backupRepository.GetBackupSchedules().Where(schedule => backupSchedule.IsToBeProcessed(schedule)).ToList(); - _logger.LogDebug("{0} backups are to schedule", backupsToSchedule.Count); + _logger.DebugBackupsSchedule(backupsToSchedule.Count); foreach (var schedule in backupsToSchedule) { @@ -115,7 +115,7 @@ public sealed class BackupSchedulerService : BackgroundService backupRepository.SaveBackupSchedule(schedule); - _logger.LogDebug("Start scheduled backup: {tenantId}, {backupMail}, {storageType}, {storageBasePath}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath); + _logger.DebugStartScheduledBackup(schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath); _eventBus.Publish(new BackupRequestIntegrationEvent( tenantId: schedule.TenantId, @@ -130,17 +130,17 @@ public sealed class BackupSchedulerService : BackgroundService } else { - _logger.LogDebug("Skip portal {tenantId} not paid", schedule.TenantId); + _logger.DebugNotPaid(schedule.TenantId); } } else { - _logger.LogDebug("Skip portal {tenantId} haven't access", schedule.TenantId); + _logger.DebugHaveNotAccess(schedule.TenantId); } } catch (Exception error) { - _logger.LogError(error, "error while scheduling backups"); + _logger.ErrorBackups(error); } } }