Skip to content

Commit

Permalink
Updated logger messages for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonbrett committed Nov 4, 2024
1 parent f42803b commit c9779a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion TrueVote.Comms/Services/CommsFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CommsFunction(IMessageProcessor messageProcessor, ILogger<CommsFunction>
[Function("ProcessCommsMessage")]
public async Task Run([ServiceBusTrigger("%ServiceBusCommsQueueName%", Connection = "ServiceBusConnectionString")] ServiceBusCommsMessage message)
{
_logger.LogInformation($"Processing message for communication event: {message.Metadata["CommunicationEventId"]}");
_logger.LogInformation($"CommsFunction->Processing message for communication event: {message.Metadata["CommunicationEventId"]}");

await _messageProcessor.ProcessMessageAsync(message);
}
Expand Down
6 changes: 3 additions & 3 deletions TrueVote.Comms/Services/CommsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task SendVoterAccessCodeEmail(string email, string accessCode, stri
{
try
{
_logger.LogInformation($"Sending voter access code email for communication event: {communicationEventId}");
_logger.LogInformation($"CommsHandler->Sending voter access code email for communication event: {communicationEventId}");

if (string.IsNullOrEmpty(accessCode))
{
Expand All @@ -37,11 +37,11 @@ await _emailService.SendEmailAsync(email, "Your TrueVote Alpha Access Code - Rea

await _apiClient.UpdateCommEventStatus(communicationEventId, "Completed", DateTime.UtcNow);

_logger.LogInformation($"Successfully sent voter access code email for communication event: {communicationEventId}");
_logger.LogInformation($"CommsHandler->Successfully sent voter access code email for communication event: {communicationEventId}");
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error sending voter access code email for communication event: {communicationEventId}");
_logger.LogError(ex, $"CommsHandler->Error sending voter access code email for communication event: {communicationEventId}");

await _apiClient.UpdateCommEventStatus(communicationEventId, "Failed", DateTime.UtcNow, ex.Message);

Expand Down
4 changes: 2 additions & 2 deletions TrueVote.Comms/Services/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public async Task SendEmailAsync(string to, string subject, EmailTemplate templa
}
catch (SmtpException ex) when (ex.Message?.Contains("Relay access denied", StringComparison.OrdinalIgnoreCase) ?? false)
{
_logger.LogInformation("Ignoring expected SMTP relay error - email still sent");
_logger.LogInformation("EmailService->Ignoring expected SMTP relay error - email still sent");
}
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error sending email to {to}");
_logger.LogError(ex, $"EmailService->Error sending email to: {to}");
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion TrueVote.Comms/Services/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MessageProcessor(ICommsHandler commsHandler, ILogger<MessageProcessor> lo

public async Task ProcessMessageAsync(ServiceBusCommsMessage message)
{
_logger.LogInformation($"Processing message for communication event: {message.Metadata["CommunicationEventId"]}");
_logger.LogInformation($"MessageProcessor->Processing message for communication event: {message.Metadata["CommunicationEventId"]}");

switch (message.Metadata["Type"])
{
Expand Down
4 changes: 2 additions & 2 deletions TrueVote.Comms/Services/ServiceBusReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task StartListeningAsync()
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing message");
_logger.LogError(ex, "AzureServiceBusReceiver->Error processing message");
throw; // Let Service Bus handle retry
}
};
Expand All @@ -60,7 +60,7 @@ public async Task CloseAsync()

private Task ExceptionHandler(ProcessErrorEventArgs args)
{
_logger.LogError(args.Exception, "Service Bus processing error");
_logger.LogError(args.Exception, "AzureServiceBusReceiver->Service Bus processing error");
return Task.CompletedTask;
}
}
12 changes: 6 additions & 6 deletions TrueVote.Comms/Services/TrueVoteApiCilent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public async Task UpdateCommEventStatus(string communicationEventId, string stat

// Log the actual response content for debugging
var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogDebug($"API Response: {response.StatusCode} - {responseContent}");
_logger.LogDebug($"ApiClient->API Response: {response.StatusCode} - {responseContent}");

if (!response.IsSuccessStatusCode)
{
_logger.LogError("Failed to update communication event {CommunicationEventId}. Status: {StatusCode}, Response: {Response}", communicationEventId, response.StatusCode, responseContent);
_logger.LogError($"ApiClient->Failed to update communication event {communicationEventId}. Status: {response.StatusCode}, Response: {responseContent}");

// Don't try to deserialize error response if it's not JSON
if (response.Content.Headers.ContentType?.MediaType == "application/json")
Expand All @@ -67,11 +67,11 @@ public async Task UpdateCommEventStatus(string communicationEventId, string stat
throw new Exception($"API Error: {response.StatusCode} - {responseContent}");
}

_logger.LogDebug($"Successfully updated communication event {communicationEventId} to {status}");
_logger.LogDebug($"ApiClient->Successfully updated communication event: {communicationEventId} to: {status}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in UpdateCommEventStatus for communication event: {CommunicationEventId}", communicationEventId);
_logger.LogError(ex, $"ApiClient-?Error in UpdateCommEventStatus for communication event: {communicationEventId}");
throw;
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public async Task<string> GetAuthTokenAsync()
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to get authentication token");
_logger.LogError(ex, "NostrAuthenticationService->Failed to get authentication token");
throw;
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ private async Task<SignInResponse> SignInToApi(SignInEventModel signInEventModel
{
var signInResponse = await response.Content.ReadFromJsonAsync<SignInResponse>() ?? throw new AuthenticationException("Empty response from API");

_logger.LogDebug($"User authenticated: {signInResponse.User.UserId}");
_logger.LogDebug($"NostrAuthenticationService->User authenticated: {signInResponse.User.UserId}");

return signInResponse;
}
Expand Down

0 comments on commit c9779a1

Please sign in to comment.