Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Distech.CloudRelay.API/Services/AzureIotHubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Distech.CloudRelay.API/Services/DeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ public async Task<DeviceResponse> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<BlobStreamDecorator> 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);
Expand Down
6 changes: 3 additions & 3 deletions src/Distech.CloudRelay.Common/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,20 @@ public async Task<int> 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<BlobInfo> responseBlobs = await m_BlobRepository.ListBlobAsync(options.DeviceFileUploadFolder);
List<BlobInfo> 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
DateTime expirationDate = DateTime.UtcNow.AddMinutes(-minutesCleanupExpirationDelay);
Task<bool>[] 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
Expand Down
2 changes: 1 addition & 1 deletion src/Distech.CloudRelay.Functions/FileStorageFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down