public static void Main(string[] args) { try { SetupConsole(); LogCurrentSettings(ConfigurationManager.AppSettings); var fileService = new Services.FileService(); var stateService = new Services.StateService(); var zipService = new Services.ZipService(); _logger.Info("##### 1. Transfer data"); fileService.DirectoryCopy(_source, _targetInstance, true); _logger.Info("##### 2. Cleanup obsolete data"); fileService.CleanDirectory(_target, _versions); _logger.Info("##### 3. Zip target"); ZipTarget(zipService); _logger.Info("##### 4. Set machine state"); SetState(stateService); _logger.Info($"All task's completed, {_source} has succesfully been backed up to {_target}"); if (Debugger.IsAttached) { Console.ReadKey(); } } catch (Exception ex) { _logger.Info("To see more verbose logging, enable 'Debug' or 'Trace' logging in the NLog.config."); _logger.Fatal(ex, "Application crashed:"); throw; } }
private static void SetState(Services.StateService stateService) { if (_gobacktosleep) { _logger.Trace("Putting machine to sleep"); if (stateService.Sleep(true)) { _logger.Trace("Putting machine to sleep."); } else { _logger.Error("Unable to force machine to sleep"); } } else { _logger.Trace("Skipping task, due to configuration..."); } }