Exemple #1
0
        protected override async Task SendErrorNotifierAsync(ExceptionSendNotifierContext context)
        {
            // 需不需要用 SettingProvider 来获取?
            var receivedUsers = EmailOptions.GetReceivedEmailOrDefault(context.Exception.GetType());

            if (!receivedUsers.IsNullOrWhiteSpace())
            {
                var emailTitle      = EmailOptions.DefaultTitle ?? L("SendEmailTitle");
                var templateContent = await TemplateRenderer
                                      .RenderAsync(ExceptionHandlingTemplates.SendEmail,
                                                   new
                {
                    title          = emailTitle,
                    header         = EmailOptions.DefaultContentHeader ?? L("SendEmailHeader"),
                    type           = context.Exception.GetType().FullName,
                    message        = context.Exception.Message,
                    loglevel       = context.LogLevel.ToString(),
                    triggertime    = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                    sendstacktrace = EmailOptions.SendStackTrace,
                    stacktrace     = context.Exception.ToString(),
                    footer         = EmailOptions.DefaultContentFooter ?? "Copyright to LINGYUN © 2020"
                });

                await EmailSender.SendAsync(receivedUsers,
                                            emailTitle,
                                            templateContent);
            }
        }
        protected override async Task SendErrorNotifierAsync(ExceptionSendNotifierContext context)
        {
            var notificationDispatcher = context.ServiceProvider.GetRequiredService <INotificationDispatcher>();
            var notificationName       = NotificationNameNormalizer
                                         .NormalizerName(AbpExceptionHandlingNotificationNames.NotificationName);
            var notificationData = new NotificationData();

            // 写入通知数据
            //TODO:集成TextTemplate完成格式化的推送
            notificationData.WriteStandardData(
                context.Exception.GetType().FullName, context.Exception.Message,
                DateTime.Now, "System");

            await notificationDispatcher.DispatchAsync(notificationName, notificationData,
                                                       CurrentTenant.Id, NotificationSeverity.Error);
        }