diff --git a/src/Distech.CloudRelay.API/Middleware/ApplicationErrorHandlerMiddleware.cs b/src/Distech.CloudRelay.API/Middleware/ApplicationErrorHandlerMiddleware.cs index 3b61464..13b453d 100644 --- a/src/Distech.CloudRelay.API/Middleware/ApplicationErrorHandlerMiddleware.cs +++ b/src/Distech.CloudRelay.API/Middleware/ApplicationErrorHandlerMiddleware.cs @@ -183,7 +183,7 @@ private void LogException(Exception ex, HttpContext context) */ // log exception to all registered targets - m_Logger.LogError(ex, $"Unhandled exception while executing the request {requestURL}"); + m_Logger.LogError(ex, "Unhandled exception while executing the request {requestURL}", requestURL); } #endregion diff --git a/src/Distech.CloudRelay.API/Services/AzureIotHubAdapter.cs b/src/Distech.CloudRelay.API/Services/AzureIotHubAdapter.cs index 17b79e8..7c2225e 100644 --- a/src/Distech.CloudRelay.API/Services/AzureIotHubAdapter.cs +++ b/src/Distech.CloudRelay.API/Services/AzureIotHubAdapter.cs @@ -110,13 +110,13 @@ private bool TryHandleIotHubException(string deviceId, IotHubException iotHubExc // thrown when an attempt to communicate with the IoT Hub fails case IotHubCommunicationException ex: - m_Logger.LogWarning($"An IotHubCommunicationException occurred: {ex}"); + m_Logger.LogWarning(ex, $"An IotHubCommunicationException occurred"); apiException = new CommunicationException(ErrorCodes.CommunicationError, ex.Message, ex); break; // thrown when the IoT Hub returns an error code (i.e. device registration is disable which prevent the actual device from establishing a connection) case ServerErrorException ex: - m_Logger.LogWarning($"A ServerErrorException occurred: {ex}"); + m_Logger.LogWarning(ex, "A ServerErrorException occurred"); apiException = new CommunicationException(ErrorCodes.GatewayError, ErrorMessages.GetGatewayErrorMessage(), ex); break; @@ -133,7 +133,7 @@ private bool TryHandleIotHubException(string deviceId, IotHubException iotHubExc // thrown when an error occurs during device client operation (i.e. device doesn't repond within the configured time out) // shall always be kept last case IotHubException ex: - m_Logger.LogWarning($"An IotHubException occurred: {ex}"); + m_Logger.LogWarning(ex, "An IotHubException occurred"); apiException = new OperationException(ErrorCodes.DeviceOperationError, ErrorMessages.GetOperationErrorMessage(), ex); break; diff --git a/src/Distech.CloudRelay.API/Services/DeviceService.cs b/src/Distech.CloudRelay.API/Services/DeviceService.cs index 9e1e367..1c9779d 100644 --- a/src/Distech.CloudRelay.API/Services/DeviceService.cs +++ b/src/Distech.CloudRelay.API/Services/DeviceService.cs @@ -115,18 +115,18 @@ public async Task InvokeRequestAsync(string deviceId, DeviceRequ // verify whether a status code was received (throwing an exception here is likely to break previous integrations) // 200 OK will be returned to the client if none of the response statuses are set if (response.Status == null && response.Headers?.Status == null) - m_Logger.LogWarning($"Response status not set."); + m_Logger.LogWarning("Response status not set."); return response; } catch(JsonReaderException ex) { - m_Logger.LogWarning($"A JsonReaderException occurred: {ex}"); + m_Logger.LogWarning(ex, "A JsonReaderException occurred"); throw new InvalidResultException(ErrorCodes.InvalidResult, ErrorMessages.GetInvalidResultMessage(), ex); } catch (JsonSerializationException ex) { - m_Logger.LogWarning($"A JsonSerializationException occurred: {ex}"); + m_Logger.LogWarning(ex, "A JsonSerializationException occurred"); throw new InvalidResultException(ErrorCodes.InvalidResult, ErrorMessages.GetInvalidResultMessage(), ex); } } diff --git a/src/Distech.CloudRelay.Common/DAL/AzureBlobStorageBlobRepository.cs b/src/Distech.CloudRelay.Common/DAL/AzureBlobStorageBlobRepository.cs index 8ed6bf9..88ac8a9 100644 --- a/src/Distech.CloudRelay.Common/DAL/AzureBlobStorageBlobRepository.cs +++ b/src/Distech.CloudRelay.Common/DAL/AzureBlobStorageBlobRepository.cs @@ -138,7 +138,7 @@ public async Task OpenBlobAsync(string blobPath) { if (ex.ErrorCode == BlobErrorCode.ContainerNotFound) { - m_Logger.LogWarning($"Container '{blob.BlobContainerName}' does not exist"); + m_Logger.LogWarning("Container '{BlobContainerName}' does not exist", blob.BlobContainerName); } throw new IdNotFoundException(ErrorCodes.BlobNotFound, blobPath); diff --git a/src/Distech.CloudRelay.Common/Services/FileService.cs b/src/Distech.CloudRelay.Common/Services/FileService.cs index 8f5bffd..3478d72 100644 --- a/src/Distech.CloudRelay.Common/Services/FileService.cs +++ b/src/Distech.CloudRelay.Common/Services/FileService.cs @@ -134,12 +134,12 @@ public async Task CleanUpFilesAsync(uint minutesCleanupExpirationDelay) //collect blobs for relay api -> device requests - any blobs in that path have been uploaded for the relay API purpose blobs = await m_BlobRepository.ListBlobAsync(options.ServerFileUploadFolder); - m_Logger.LogDebug($"Found '{blobs.Count}' blob(s) for relay -> device requests"); + m_Logger.LogDebug("Found '{blobCount}' blob(s) for relay -> device requests", blobs.Count); //collect blobs for device -> relay api responses - filter blobs related to relay API context only List responseBlobs = await m_BlobRepository.ListBlobAsync(options.DeviceFileUploadFolder); List relayApiBlobs = responseBlobs.Where(b => b.Path.Contains(m_FileStorageOptions.Value.ServerFileUploadSubFolder)).ToList(); - m_Logger.LogDebug($"Found '{relayApiBlobs.Count}' blob(s) for device -> relay responses"); + m_Logger.LogDebug("Found '{relayApiBlobsCount}' blob(s) for device -> relay responses", relayApiBlobs.Count); blobs.AddRange(relayApiBlobs); //select expired blobs only @@ -147,7 +147,7 @@ public async Task CleanUpFilesAsync(uint minutesCleanupExpirationDelay) Task[] deleteTasks = blobs.Where(b => b.LastModified < expirationDate) .Select(b => m_BlobRepository.DeleteBlobAsync(b.Path)) .ToArray(); - m_Logger.LogDebug($"Found '{deleteTasks.Count()}' expired blob(s)"); + m_Logger.LogDebug("Found '{deleteTasksCount}' expired blob(s)", deleteTasks.Length); //parrallel delete ends up degrading performances when dealing with large amount of blobs (longer latencies and throttling) and could also ends up reaching the host maximum number of outbound connections. //the current implementation does not allow to control the amount of HttpClient created by the CloudBlobClient: https://github.com/Azure/azure-storage-net/issues/580 diff --git a/src/Distech.CloudRelay.Functions/FileStorageFunctions.cs b/src/Distech.CloudRelay.Functions/FileStorageFunctions.cs index 70192c9..6bdf83a 100644 --- a/src/Distech.CloudRelay.Functions/FileStorageFunctions.cs +++ b/src/Distech.CloudRelay.Functions/FileStorageFunctions.cs @@ -56,7 +56,7 @@ public async Task CleanupExpiredBlobsAsync([TimerTrigger("0 0 0 * * sun")]TimerI uint delay = m_Options.Value.MinutesExpirationDelay ?? DefaultMinutesExpirationDelay; string expirationDate = DateTime.UtcNow.AddMinutes(-delay).ToString(); int deleted = await m_FileService.CleanUpFilesAsync(delay); - m_Logger.LogInformation($"Cleaned-up '{deleted}' expired blob(s) since {expirationDate}"); + m_Logger.LogInformation("Cleaned-up '{deleted}' expired blob(s) since {expirationDate}", deleted, expirationDate); } #endregion