diff --git a/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs b/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs index b6befe539c..b0f05218d0 100644 --- a/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs +++ b/src/MaaWpfGui/Services/Notification/ExternalNotificationService.cs @@ -11,10 +11,12 @@ // but WITHOUT ANY WARRANTY // +using System; using System.Collections.Generic; using System.Threading.Tasks; using MaaWpfGui.Constants; using MaaWpfGui.Helper; +using Serilog; namespace MaaWpfGui.Services.Notification { @@ -22,6 +24,8 @@ namespace MaaWpfGui.Services.Notification { private static readonly List _taskContainers = new List(); + private static readonly ILogger _logger = Log.Logger; + private static async Task SendAsync(string title, string content, bool isTest = false) { var enabledProvider = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnabled, "Off"); @@ -33,14 +37,24 @@ namespace MaaWpfGui.Services.Notification _ => new DummyNotificationProvider(), }; - var result = await provider.SendAsync(title, content); + var result = false; + try + { + result = await provider.SendAsync(title, content); + } + catch (Exception ex) + { + _logger.Error(ex, "Failed to send External Notifications"); + } if (isTest is false && result) { return; } - using var toast = new ToastNotification(LocalizationHelper.GetString(result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail")); + using var toast = new ToastNotification( + LocalizationHelper.GetString( + result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail")); toast.Show(); }