public void Process() { try { foreach (var builder in LoadCsvBuilders(_db)) { builder.GenerateCsv(); } BuilderBase.Compress(_logger); // Retain only the last x files (based on config setting) foreach (FileInfo fi in new DirectoryInfo(Constants.ConfigSettings.NightlyCsvFilesDirectoryLocation).GetFiles("*.zip").OrderByDescending(x => x.CreationTimeUtc).Skip(Constants.ConfigSettings.NumberOfZipFilesToRetain)) { fi.Delete(); } } catch (Exception ex) { NotifyException(ex); _logger(string.Concat(ex.Message, ex.StackTrace)); } }