/// <summary> /// Starts the backup engines. /// </summary> /// <returns>True if successful, otherwise false.</returns> private async Task <bool> StartBackupEnginesAsync() { // each backup engine instance shares the same logger. // this means a single log file for all engine instances- and each engine will prepend its log messages with a context tag. try { BackupEngineInstances = new List <BackupEngine>(); var instanceCountSettingName = ArchivialLibrary.Constants.RuntimeSettingNames.BackupEngineInstancesCount; var instanceCount = Convert.ToInt32(await ClientDatabase.GetApplicationOptionAsync(instanceCountSettingName).ConfigureAwait(false)); var startupDelaySettingName = ArchivialLibrary.Constants.RuntimeSettingNames.BackupEngineStartupDelayInSeconds; var startupDelaySeconds = Convert.ToInt32(await ClientDatabase.GetApplicationOptionAsync(startupDelaySettingName).ConfigureAwait(false)); for (int i = 0; i < instanceCount; i++) { CoreLog.WriteSystemEvent( string.Format("Waiting {0} seconds between Backup Engine starts to reduce sudden filesystem load.", startupDelaySeconds), EventLogEntryType.Information, ArchivialLibrary.Constants.EventIDs.BackupEngineWaitingForNextStart, true); await Task.Delay(TimeSpan.FromSeconds(startupDelaySeconds)).ConfigureAwait(false); var engineLog = new Logger(string.Format("{0}-{1}", ArchivialLibrary.Constants.Logging.BackupComponentName, i)); engineLog.Start( CoreSettings.GetEventlogName(), CoreSettings.GetEventlogName(), CoreSettings.GetLogFilesDirectory()); var instance = new BackupEngine(ClientDatabase, engineLog, i, CoreSettings); instance.Stopped += Backup_Stopped; instance.BeginStart(); BackupEngineInstances.Add(instance); CoreLog.WriteSystemEvent( string.Format("Backup Engine instance {0} has started.", i), EventLogEntryType.Information, ArchivialLibrary.Constants.EventIDs.StartedBackupEngine, true); } return(true); } catch (Exception ex) { var message = "Failed to start the backup engine."; var context = CoreLog.GenerateFullContextStackTrace(); CoreLog.WriteSystemEvent(message, ex, context, ArchivialLibrary.Constants.EventIDs.FailedBackupEngine, true); return(false); } }
/// <summary> /// Starts the shared logging instances. /// </summary> private void StartLoggers() { CoreLog = new Logger(ArchivialLibrary.Constants.Logging.CoreServiceComponentName); CoreLog.Start( CoreSettings.GetEventlogName(), CoreSettings.GetEventlogName(), CoreSettings.GetLogFilesDirectory()); ScanEngineLog = new Logger(ArchivialLibrary.Constants.Logging.ScanningComponentName); ScanEngineLog.Start( CoreSettings.GetEventlogName(), CoreSettings.GetEventlogName(), CoreSettings.GetLogFilesDirectory()); }
/// <summary> /// Starts the cleanup engine(s). /// </summary> /// <returns>True if successful, otherwise false.</returns> private async Task <bool> StartCleanupEnginesAsync() { // each cleanup engine instance shares the same logger. // this means a single log file for all engine instances- and each engine will prepend its log messages with a context tag. try { CleanupEngineInstances = new List <CleanupEngine>(); var settingName = ArchivialLibrary.Constants.RuntimeSettingNames.CleanupEngineInstancesCount; var instanceCount = Convert.ToInt32(await ClientDatabase.GetApplicationOptionAsync(settingName).ConfigureAwait(false)); for (int i = 0; i < instanceCount; i++) { var engineLog = new Logger(string.Format("{0}-{1}", ArchivialLibrary.Constants.Logging.CleanupComponentName, i)); engineLog.Start( CoreSettings.GetEventlogName(), CoreSettings.GetEventlogName(), CoreSettings.GetLogFilesDirectory()); var instance = new CleanupEngine(ClientDatabase, engineLog, i, CoreSettings); instance.Stopped += Cleanup_Stopped; instance.BeginStart(); CleanupEngineInstances.Add(instance); CoreLog.WriteSystemEvent( string.Format("Cleanup Engine instance {0} has started.", i), EventLogEntryType.Information, ArchivialLibrary.Constants.EventIDs.StartedCleanupEngine, true); } return(true); } catch (Exception ex) { var message = "Failed to start the cleanup engine(s)."; var context = CoreLog.GenerateFullContextStackTrace(); CoreLog.WriteSystemEvent(message, ex, context, ArchivialLibrary.Constants.EventIDs.FailedCleanupEngine, true); return(false); } }