diff --git a/src/FilterLists.Agent/Logger.cs b/src/FilterLists.Agent/Logger.cs index a99e9f0cf..4a5a36bc9 100644 --- a/src/FilterLists.Agent/Logger.cs +++ b/src/FilterLists.Agent/Logger.cs @@ -26,5 +26,11 @@ public void Log(string message) Console.WriteLine(message); telemetryClient.TrackTrace(message); } + + public void Log(Exception e) + { + Console.WriteLine(e.Message); + telemetryClient.TrackException(e); + } } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Program.cs b/src/FilterLists.Agent/Program.cs index a4b00d610..ebf71e739 100644 --- a/src/FilterLists.Agent/Program.cs +++ b/src/FilterLists.Agent/Program.cs @@ -1,4 +1,6 @@ -using System.IO; +using System; +using System.IO; +using System.Threading.Tasks; using FilterLists.Services.DependencyInjection.Extensions; using FilterLists.Services.Snapshot; using Microsoft.Extensions.Configuration; @@ -41,10 +43,22 @@ private static void BuildServiceProvider() private static void CaptureSnapshots(int batchSize) { - var snapshotService = serviceProvider.GetService(); logger.Log("Capturing FilterList snapshots..."); - snapshotService.CaptureAsync(batchSize).Wait(); + TryCaptureAsync(batchSize).Wait(); logger.Log("Snapshots captured."); } + + private static async Task TryCaptureAsync(int batchSize) + { + var snapshotService = serviceProvider.GetService(); + try + { + await snapshotService.CaptureAsync(batchSize); + } + catch (Exception e) + { + logger.Log(e); + } + } } } \ No newline at end of file