removed duplicated method

master
Tudor Stanciu 2023-01-21 04:41:05 +02:00
parent b75793a08a
commit 826bee7db6
5 changed files with 10 additions and 19 deletions

View File

@ -5,7 +5,10 @@ namespace Correo.Abstractions.Extensions
{ {
public static class ModelExtensions public static class ModelExtensions
{ {
public static string Log(this IEnumerable<EmailMessage.MailAddress> addresses) private static string Log(this IEnumerable<EmailMessage.MailAddress> addresses)
=> addresses != null ? string.Join(',', addresses.Select(z => z.Address)) : string.Empty; => addresses != null ? string.Join(',', addresses.Select(z => z.Address)) : string.Empty;
public static string Log(this EmailMessage message)
=> $"Email sent: Subject: {message.Subject}; From: {message.From.Address}; To: {message.To.Log()}; Cc: {message.Cc.Log()}; Bcc: {message.Bcc.Log()};";
} }
} }

View File

@ -47,17 +47,14 @@ namespace Correo.MailKit
{ {
var mailMessage = message.ToMailMessage(); var mailMessage = message.ToMailMessage();
_smtpClient.Send(mailMessage); _smtpClient.Send(mailMessage);
Log(message); _logger.LogInformation(message.Log());
} }
public async Task SendEmailAsync(EmailMessage message, CancellationToken token = default) public async Task SendEmailAsync(EmailMessage message, CancellationToken token = default)
{ {
var mailMessage = message.ToMailMessage(); var mailMessage = message.ToMailMessage();
await _smtpClient.SendAsync(mailMessage, token); await _smtpClient.SendAsync(mailMessage, token);
Log(message); _logger.LogInformation(message.Log());
} }
private void Log(EmailMessage message)
=> _logger.LogInformation($"Email sent: Subject: {message.Subject}; From: {message.From.Address}; To: {message.To.Log()}; Cc: {message.Cc.Log()}; Bcc: {message.Bcc.Log()};");
} }
} }

View File

@ -65,15 +65,12 @@ namespace Correo.Mailgun
if (response.IsSuccessful) if (response.IsSuccessful)
{ {
_logger.LogInformation($"Mailgun response: {response.Data.Message} {response.Data.Id}"); _logger.LogInformation($"Mailgun response: {response.Data.Message} {response.Data.Id}");
Log(message); _logger.LogInformation(message.Log());
} }
else else
{ {
throw new Exception($"Mailgun error: {response.Data.Message}"); throw new Exception($"Mailgun error: {response.Data.Message}");
} }
} }
private void Log(EmailMessage message)
=> _logger.LogInformation($"Email sent: Subject: {message.Subject}; From: {message.From.Address}; To: {message.To.Log()}; Cc: {message.Cc.Log()}; Bcc: {message.Bcc.Log()};");
} }
} }

View File

@ -49,17 +49,14 @@ namespace Correo.NetSmtpClient
{ {
var mailMessage = message.ToMailMessage(); var mailMessage = message.ToMailMessage();
_smtpClient.Send(mailMessage); _smtpClient.Send(mailMessage);
Log(message); _logger.LogInformation(message.Log());
} }
public async Task SendEmailAsync(EmailMessage message, CancellationToken token = default) public async Task SendEmailAsync(EmailMessage message, CancellationToken token = default)
{ {
var mailMessage = message.ToMailMessage(); var mailMessage = message.ToMailMessage();
await _smtpClient.SendMailAsync(mailMessage, token); await _smtpClient.SendMailAsync(mailMessage, token);
Log(message); _logger.LogInformation(message.Log());
} }
private void Log(EmailMessage message)
=> _logger.LogInformation($"Email sent: Subject: {message.Subject}; From: {message.From.Address}; To: {message.To.Log()}; Cc: {message.Cc.Log()}; Bcc: {message.Bcc.Log()};");
} }
} }

View File

@ -36,7 +36,7 @@ namespace Correo.SendGrid
var mailMessage = message.ToSendGridMessage(); var mailMessage = message.ToSendGridMessage();
var response = await _client.SendEmailAsync(mailMessage, token); var response = await _client.SendEmailAsync(mailMessage, token);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
Log(message); _logger.LogInformation(message.Log());
else else
{ {
var body = await response.DeserializeResponseBodyAsync(); var body = await response.DeserializeResponseBodyAsync();
@ -52,8 +52,5 @@ namespace Correo.SendGrid
throw new Exception(response.StatusCode.ToString()); throw new Exception(response.StatusCode.ToString());
} }
} }
private void Log(EmailMessage message)
=> _logger.LogInformation($"Email sent: Subject: {message.Subject}; From: {message.From.Address}; To: {message.To.Log()}; Cc: {message.Cc.Log()}; Bcc: {message.Bcc.Log()};");
} }
} }