Пример #1
0
        private async Task HandleWarningLogsAsync()
        {
            if (DateTime.UtcNow - _warningLogsLastUpdatedAt < TimeSpan.FromSeconds(_appConfig.WarningLogsSendInterval))
            {
                return;
            }

            var logs = _logStore.GetLevel(LogLevel.Warning);

            if (!logs.Any())
            {
                return;
            }

            var message = new StringBuilder();

            foreach (var log in logs)
            {
                message.AppendLine($"<p><details>{log}</details></p>");
            }

            message.AppendLine($"<p><small>generated at {DateTime.UtcNow.ToChinaTime().ToDateAndTime()}.</small></p>");
            await _emailClient.SendAsync(
                BlogConstant.LogSenderName,
                BlogConstant.LogSenderEmail,
                BlogConstant.AuthorEnglishName,
                BlogConstant.AuthorEmail,
                "WARNING LOGS!",
                message.ToString());

            _warningLogsLastUpdatedAt = DateTime.UtcNow;
        }