Skip to content

Commit 579da2f

Browse files
committed
minor tweaks
1 parent 150c2a1 commit 579da2f

File tree

20 files changed

+98
-49
lines changed

20 files changed

+98
-49
lines changed

samples/EntityFramework/src/Tracker.Host/Tracker.Host.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.4.0" />
15+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.4.1" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

samples/EntityFramework/src/Tracker.Web/Tracker.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.8" />
1919
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.4.1" />
20-
<PackageReference Include="Microsoft.Identity.Web" Version="3.13.0" />
20+
<PackageReference Include="Microsoft.Identity.Web" Version="3.13.1" />
2121
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
2222
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
2323
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />

samples/MongoDB/Tracker.WebService/Tracker.WebService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="AspNetCore.SecurityKey" Version="2.3.1" />
16+
<PackageReference Include="AspNetCore.SecurityKey" Version="3.0.0" />
1717
<PackageReference Include="AutoMapper" Version="[14.0.0]" />
1818
<PackageReference Include="FluentValidation" Version="12.0.0" />
1919
<PackageReference Include="Injectio" Version="5.0.0" PrivateAssets="All" />

src/Arbiter.CommandQuery.Endpoints/DispatcherEndpoint.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Arbiter.CommandQuery.Endpoints;
1515
/// <summary>
1616
/// Defines an endpoint for dispatching commands using the Mediator pattern.
1717
/// </summary>
18-
public class DispatcherEndpoint : IEndpointRoute
18+
public partial class DispatcherEndpoint : IEndpointRoute
1919
{
2020
private readonly DispatcherOptions _dispatcherOptions;
2121
private readonly ILogger<DispatcherEndpoint> _logger;
@@ -65,19 +65,23 @@ protected virtual async Task<Results<Ok<object>, ProblemHttpResult>> Send(
6565
ClaimsPrincipal? user = default,
6666
CancellationToken cancellationToken = default)
6767
{
68+
var request = dispatchRequest.Request;
69+
6870
try
6971
{
70-
var request = dispatchRequest.Request;
71-
7272
var result = await mediator.Send(request, cancellationToken).ConfigureAwait(false);
7373
return TypedResults.Ok(result);
7474
}
7575
catch (Exception ex)
7676
{
77-
_logger.LogError(ex, "Error dispatching request: {ErrorMessage}", ex.Message);
77+
LogDispatchError(_logger, request?.GetType()?.FullName, ex.Message, ex);
7878

7979
var details = ex.ToProblemDetails();
8080
return TypedResults.Problem(details);
8181
}
8282
}
83+
84+
85+
[LoggerMessage(1, LogLevel.Error, "Error dispatching request '{RequestType}': {ErrorMessage}")]
86+
static partial void LogDispatchError(ILogger logger, string? requestType, string errorMessage, Exception exception);
8387
}

src/Arbiter.Communication.Azure/AzureEmailDeliveryService.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Arbiter.Communication.Azure;
1212
/// <summary>
1313
/// Provides an implementation of <see cref="IEmailDeliveryService"/> that delivers emails using Azure Communication Services.
1414
/// </summary>
15-
public class AzureEmailDeliveryService : IEmailDeliveryService
15+
public partial class AzureEmailDeliveryService : IEmailDeliveryService
1616
{
1717
private readonly ILogger<AzureEmailDeliveryService> _logger;
1818
private readonly Ace.EmailClient _emailClient;
@@ -44,7 +44,7 @@ public async Task<EmailResult> Send(
4444
var recipients = emailMessage.Recipients.ToString();
4545
var truncatedSubject = emailMessage.Content.Subject.Truncate(20);
4646

47-
_logger.LogDebug("Sending email to '{Recipients}' with subject '{Subject}' using Azure Communication", recipients, truncatedSubject);
47+
LogSendingEmailAzure(_logger, recipients, truncatedSubject);
4848

4949
try
5050
{
@@ -54,16 +54,16 @@ public async Task<EmailResult> Send(
5454

5555
if (sendOperation.Value.Status == Ace.EmailSendStatus.Succeeded)
5656
{
57-
_logger.LogInformation("Sent email to '{Recipients}' with subject '{Subject}'", recipients, truncatedSubject);
57+
LogEmailSentAzure(_logger, recipients, truncatedSubject);
5858
return EmailResult.Success("Email sent successfully.");
5959
}
6060

61-
_logger.LogError("Error sending email to '{Recipients}' with subject '{Subject}'; Status: {Status}", recipients, truncatedSubject, sendOperation.Value.Status);
61+
LogEmailSendErrorAzure(_logger, recipients, truncatedSubject, sendOperation.Value.Status);
6262
return EmailResult.Fail($"Email send failed with status {sendOperation.Value.Status}");
6363
}
6464
catch (Exception ex)
6565
{
66-
_logger.LogError(ex, "Error sending email to '{Recipients}' with subject '{Subject}': {ErrorMessage}", recipients, truncatedSubject, ex.Message);
66+
LogEmailSendExceptionAzure(_logger, recipients, truncatedSubject, ex.Message, ex);
6767
return EmailResult.Fail("An error occurred while sending the email", ex);
6868
}
6969
}
@@ -117,4 +117,17 @@ private static Ace.EmailMessage ConvertMessage(EmailMessage emailMessage)
117117

118118
return message;
119119
}
120+
121+
122+
[LoggerMessage(1, LogLevel.Debug, "Sending email to '{Recipients}' with subject '{Subject}' using Azure Communication")]
123+
static partial void LogSendingEmailAzure(ILogger logger, string recipients, string subject);
124+
125+
[LoggerMessage(2, LogLevel.Information, "Sent email to '{Recipients}' with subject '{Subject}'")]
126+
static partial void LogEmailSentAzure(ILogger logger, string recipients, string subject);
127+
128+
[LoggerMessage(3, LogLevel.Error, "Error sending email to '{Recipients}' with subject '{Subject}'; Status: {Status}")]
129+
static partial void LogEmailSendErrorAzure(ILogger logger, string recipients, string subject, Ace.EmailSendStatus status);
130+
131+
[LoggerMessage(4, LogLevel.Error, "Error sending email to '{Recipients}' with subject '{Subject}': {ErrorMessage}")]
132+
static partial void LogEmailSendExceptionAzure(ILogger logger, string recipients, string subject, string errorMessage, Exception exception);
120133
}

src/Arbiter.Communication.Azure/AzureSmsDeliveryService.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Arbiter.Communication.Azure;
1111
/// <summary>
1212
/// Provides an implementation of <see cref="ISmsDeliveryService"/> that delivers SMS messages using Azure Communication Services.
1313
/// </summary>
14-
public class AzureSmsDeliveryService : ISmsDeliveryService
14+
public partial class AzureSmsDeliveryService : ISmsDeliveryService
1515
{
1616
private readonly ILogger<AzureSmsDeliveryService> _logger;
1717
private readonly SmsClient _smsClient;
@@ -44,7 +44,7 @@ public async Task<SmsResult> Send(SmsMessage message, CancellationToken cancella
4444
var truncatedMessage = message.Message.Truncate(20);
4545
var senderNumber = message.Sender.HasValue() ? message.Sender : _options.Value.SenderNumber;
4646

47-
_logger.LogDebug("Sending SMS to '{Recipient}' from '{Sender} with message '{Message}' using Azure Communication", message.Recipient, senderNumber, truncatedMessage);
47+
LogSendingSms(_logger, message.Recipient, senderNumber, truncatedMessage);
4848

4949
try
5050
{
@@ -59,17 +59,30 @@ public async Task<SmsResult> Send(SmsMessage message, CancellationToken cancella
5959

6060
if (results.Value.Successful)
6161
{
62-
_logger.LogInformation("Sent SMS to '{Recipients}' with message '{Message}'", message.Recipient, truncatedMessage);
62+
LogSmsSent(_logger, message.Recipient, truncatedMessage);
6363
return SmsResult.Success("SMS sent successfully.");
6464
}
6565

66-
_logger.LogError("Error sending SMS to '{Recipients}' with message '{Message}'", message.Recipient, truncatedMessage);
66+
LogSmsSendError(_logger, message.Recipient, truncatedMessage);
6767
return SmsResult.Fail($"Error sending SMS: {results.Value.ErrorMessage}");
6868
}
6969
catch (Exception ex)
7070
{
71-
_logger.LogError(ex, "Error sending SMS to '{Recipients}' with message '{Message}': {ErrorMessage}", message.Recipient, truncatedMessage, ex.Message);
71+
LogSmsSendException(_logger, message.Recipient, truncatedMessage, ex.Message, ex);
7272
return SmsResult.Fail("An error occurred while sending the SMS", ex);
7373
}
7474
}
75+
76+
77+
[LoggerMessage(1, LogLevel.Debug, "Sending SMS to '{Recipient}' from '{Sender} with message '{Message}' using Azure Communication")]
78+
static partial void LogSendingSms(ILogger logger, string recipient, string? sender, string message);
79+
80+
[LoggerMessage(2, LogLevel.Information, "Sent SMS to '{Recipient}' with message '{Message}'")]
81+
static partial void LogSmsSent(ILogger logger, string recipient, string message);
82+
83+
[LoggerMessage(3, LogLevel.Error, "Error sending SMS to '{Recipient}' with message '{Message}'")]
84+
static partial void LogSmsSendError(ILogger logger, string recipient, string message);
85+
86+
[LoggerMessage(4, LogLevel.Error, "Error sending SMS to '{Recipient}' with message '{Message}': {ErrorMessage}")]
87+
static partial void LogSmsSendException(ILogger logger, string recipient, string message, string errorMessage, Exception exception);
7588
}

src/Arbiter.Communication.Twilio/Arbiter.Communication.Twilio.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1111
<PackageReference Include="SendGrid.Extensions.DependencyInjection" Version="1.0.1" />
1212
<PackageReference Include="starkbank-ecdsa" Version="1.3.3" />
13-
<PackageReference Include="Twilio" Version="7.12.0" />
13+
<PackageReference Include="Twilio" Version="7.12.1" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/Arbiter.Communication.Twilio/SendGridEmailDeliveryService.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Arbiter.Communication.Twilio;
1111
/// <summary>
1212
/// Provides an implementation of <see cref="IEmailDeliveryService"/> that delivers emails using SendGrid.
1313
/// </summary>
14-
public class SendGridEmailDeliveryService : IEmailDeliveryService
14+
public partial class SendGridEmailDeliveryService : IEmailDeliveryService
1515
{
1616
private readonly ILogger<SendGridEmailDeliveryService> _logger;
1717
private readonly ISendGridClient _sendGridClient;
@@ -43,7 +43,7 @@ public async Task<EmailResult> Send(
4343
var recipients = emailMessage.Recipients.ToString();
4444
var truncatedSubject = emailMessage.Content.Subject.Truncate(20);
4545

46-
_logger.LogDebug("Sending email to '{Recipients}' with subject '{Subject}' using SendGrid", recipients, truncatedSubject);
46+
LogSendingEmailSendGrid(_logger, recipients, truncatedSubject);
4747

4848
try
4949
{
@@ -55,16 +55,16 @@ public async Task<EmailResult> Send(
5555

5656
if (response.IsSuccessStatusCode)
5757
{
58-
_logger.LogInformation("Sent email to '{Recipients}' with subject '{Subject}'", recipients, truncatedSubject);
58+
LogEmailSentSendGrid(_logger, recipients, truncatedSubject);
5959
return EmailResult.Success("Email sent successfully.");
6060
}
6161

62-
_logger.LogError("Error sending email to '{Recipients}' with subject '{Subject}'; Status: {Status}", recipients, truncatedSubject, response.StatusCode);
62+
LogEmailSendErrorSendGrid(_logger, recipients, truncatedSubject, response.StatusCode);
6363
return EmailResult.Fail($"Email send failed with status {response.StatusCode}");
6464
}
6565
catch (Exception ex)
6666
{
67-
_logger.LogError(ex, "Error sending email to '{Recipients}' with subject '{Subject}': {ErrorMessage}", recipients, truncatedSubject, ex.Message);
67+
LogEmailSendExceptionSendGrid(_logger, recipients, truncatedSubject, ex.Message, ex);
6868
return EmailResult.Fail("An error occurred while sending the email", ex);
6969
}
7070
}
@@ -126,4 +126,17 @@ private static SendGridMessage ConvertMessage(EmailMessage emailMessage)
126126

127127
private static SendGrid.Helpers.Mail.EmailAddress ConvertEmail(Email.EmailAddress emailAddress)
128128
=> new(emailAddress.Address, emailAddress.DisplayName);
129+
130+
131+
[LoggerMessage(1, LogLevel.Debug, "Sending email to '{Recipients}' with subject '{Subject}' using SendGrid")]
132+
static partial void LogSendingEmailSendGrid(ILogger logger, string recipients, string subject);
133+
134+
[LoggerMessage(2, LogLevel.Information, "Sent email to '{Recipients}' with subject '{Subject}'")]
135+
static partial void LogEmailSentSendGrid(ILogger logger, string recipients, string subject);
136+
137+
[LoggerMessage(3, LogLevel.Error, "Error sending email to '{Recipients}' with subject '{Subject}'; Status: {Status}")]
138+
static partial void LogEmailSendErrorSendGrid(ILogger logger, string recipients, string subject, System.Net.HttpStatusCode status);
139+
140+
[LoggerMessage(4, LogLevel.Error, "Error sending email to '{Recipients}' with subject '{Subject}': {ErrorMessage}")]
141+
static partial void LogEmailSendExceptionSendGrid(ILogger logger, string recipients, string subject, string errorMessage, Exception exception);
129142
}

src/Arbiter.Communication/DependencyInjectionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Reflection;
22

33
using Arbiter.Communication.Email;
4-
using Arbiter.Communication.Extensions;
54
using Arbiter.Communication.Sms;
65
using Arbiter.Communication.Template;
76

src/Arbiter.Communication/Email/EmailConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.ComponentModel.DataAnnotations;
2-
using System.Reflection;
32

43
namespace Arbiter.Communication.Email;
54

0 commit comments

Comments
 (0)