diff --git a/module/upms/NPin.Framework.Upms.Domain/Managers/SmsManager.cs b/module/upms/NPin.Framework.Upms.Domain/Managers/SmsManager.cs index 7e648c6..3d7ad3a 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Managers/SmsManager.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Managers/SmsManager.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Newtonsoft.Json; using NPin.Framework.SettingManagement.Domain; using NPin.Framework.Upms.Domain.Settings; @@ -12,25 +13,25 @@ namespace NPin.Framework.Upms.Domain.Managers; public class SmsManager : DomainService { - private readonly ILogger _logger; + public ILogger Logger { get; set; } private readonly ISettingManager _settingManager; private readonly IEnumerable _smsProviders; - public SmsManager(ILogger logger, ISettingManager settingManager, IEnumerable smsProviders) + public SmsManager(ISettingManager settingManager, IEnumerable smsProviders) { - _logger = logger; + Logger = NullLogger.Instance; _settingManager = settingManager; _smsProviders = smsProviders; } public async Task GetSmsConfigModelAsync() { - var configJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsConfigModelKey); - var settingsJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsSettingsKey); - var providersJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsProvidersKey); - var templateJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsTemplatesKey); + var configJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsConfigModel); + var settingsJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsSettings); + var providersJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsProviders); + var templateJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsTemplates); var ret = JsonConvert.DeserializeObject(configJson ?? string.Empty) ?? new SmsConfigModel(); @@ -71,7 +72,7 @@ public class SmsManager : DomainService } catch (Exception ex) { - _logger.LogError(ex, $"短信发送失败: {ex.Message}"); + Logger.LogError(ex, $"短信发送失败: {ex.Message}"); throw new UserFriendlyException($"短信发送失败: {ex.Message}"); } } diff --git a/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/AliyunSmsHandler.cs b/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/AliyunSmsHandler.cs index f72c861..7b365f1 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/AliyunSmsHandler.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/AliyunSmsHandler.cs @@ -2,6 +2,7 @@ using AlibabaCloud.SDK.Dysmsapi20170525; using AlibabaCloud.SDK.Dysmsapi20170525.Models; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Newtonsoft.Json; using NPin.Framework.Upms.Domain.Shared.Enums; using NPin.Framework.Upms.Domain.Shared.Model; @@ -11,11 +12,11 @@ namespace NPin.Framework.Upms.Domain.Sms.Handler; public class AliyunSmsHandler : ISms, ISingletonDependency { - private readonly ILogger _logger; + public ILogger Logger { get; set; } - public AliyunSmsHandler(ILogger logger) + public AliyunSmsHandler() { - _logger = logger; + Logger = NullLogger.Instance; } public SmsProviderTypeEnum ProviderType => SmsProviderTypeEnum.Aliyun; @@ -37,7 +38,7 @@ public class AliyunSmsHandler : ISms, ISingletonDependency var response = await client.SendSmsAsync(sendSmsRequest); // TODO 判断结果 - _logger.LogDebug(response.ToString()); + Logger.LogDebug(response.ToString()); } private Client CreateClient(SmsProvider provider) diff --git a/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/TencentSmsHandler.cs b/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/TencentSmsHandler.cs index d3a7de8..a665599 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/TencentSmsHandler.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Sms/Handler/TencentSmsHandler.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using NPin.Framework.Upms.Domain.Shared.Enums; using NPin.Framework.Upms.Domain.Shared.Model; using TencentCloud.Common; @@ -11,11 +12,11 @@ namespace NPin.Framework.Upms.Domain.Sms.Handler; public class TencentSmsHandler : ISms, ISingletonDependency { - private readonly ILogger _logger; + public ILogger Logger { get; set; } - public TencentSmsHandler(ILogger logger) + public TencentSmsHandler() { - _logger = logger; + Logger = NullLogger.Instance; } public SmsProviderTypeEnum ProviderType => SmsProviderTypeEnum.Tencent; @@ -37,7 +38,7 @@ public class TencentSmsHandler : ISms, ISingletonDependency var response = await client.SendSms(sendSmsRequest); // TODO 判断结果 - _logger.LogDebug(response.ToString()); + Logger.LogDebug(response.ToString()); } private SmsClient CreateClient(SmsProvider provider)