using System; using System.Collections.Generic; namespace Sanhe.Abp.ExceptionHandling.Emailing; public class AbpEmailExceptionHandlingOptions { /// /// 发送堆栈信息 /// public bool SendStackTrace { get; set; } = false; /// /// 默认邮件标题 /// public string DefaultTitle { get; set; } /// /// 默认邮件内容头 /// public string DefaultContentHeader { get; set; } /// /// 默认邮件内容底 /// public string DefaultContentFooter { get; set; } /// /// 默认异常收件人 /// public string DefaultReceiveEmail { get; set; } /// /// 异常类型指定收件人处理映射列表 /// public IDictionary Handlers { get; set; } public AbpEmailExceptionHandlingOptions() { Handlers = new Dictionary(); } /// /// 把需要接受异常通知的用户加进处理列表 /// /// 处理的异常类型 /// 接收邮件的用户类别,群发用,符号分隔 public void HandReceivedException(string receivedEmails) where TException : Exception { HandReceivedException(typeof(TException), receivedEmails); } /// /// 把需要接受异常通知的用户加进处理列表 /// /// 处理的异常类型 /// 接收邮件的用户类别,群发用,符号分隔 public void HandReceivedException(Type exceptionType, string receivedEmails) { if (Handlers.ContainsKey(exceptionType)) { Handlers[exceptionType] += receivedEmails; } else { Handlers.Add(exceptionType, receivedEmails); } } public string GetReceivedEmailOrDefault(Type exceptionType) { if (Handlers.TryGetValue(exceptionType, out string receivedUsers)) { return receivedUsers; } return DefaultReceiveEmail; } }