Logger
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
if (!getFile.IsSuccess)
|
||||
{
|
||||
var errorMessage = string.Join("; ", getFile.Errors);
|
||||
logger.LogError("Failed to download file from bucket. Bucket: {BucketName}, Key: {KeyName}, Errors: {Errors}",
|
||||
logger.LogWarning("Failed to download file from bucket. Bucket: {BucketName}, Key: {KeyName}, Errors: {Errors}",
|
||||
executeContext.Arguments.BucketName,
|
||||
executeContext.Arguments.KeyName,
|
||||
errorMessage);
|
||||
|
||||
@@ -34,8 +34,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
{
|
||||
if (!File.Exists(executeContext.Arguments.SourceFilePath))
|
||||
{
|
||||
logger.LogError("Source file not found at {SourceFilePath}",
|
||||
executeContext.Arguments.SourceFilePath);
|
||||
logger.LogWarning("Source file not found at {SourceFilePath}", executeContext.Arguments.SourceFilePath);
|
||||
throw new FileNotFoundException($"Source file not found: {executeContext.Arguments.SourceFilePath}");
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
await using var destinationStream = File.Create(executeContext.Arguments.DestinationFilePath);
|
||||
await resizedPicture.Value.CopyToAsync(destinationStream, executeContext.CancellationToken);
|
||||
|
||||
logger.LogInformation("Picture resized successfully from {SourceFilePath} to {DestinationFilePath} ( {Width}x{Height} )",
|
||||
logger.LogDebug("Picture resized from {SourceFilePath} to {DestinationFilePath} ({Width}x{Height})",
|
||||
executeContext.Arguments.SourceFilePath,
|
||||
executeContext.Arguments.DestinationFilePath,
|
||||
executeContext.Arguments.Width,
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
if (!transferFilesResult.IsSuccess)
|
||||
{
|
||||
var errorMessage = string.Join("; ", transferFilesResult.Errors);
|
||||
logger.LogError("Failed to transfer files from {FolderPath} to bucket {DestinationBucketName}, key {DestinationKeyName}. Errors: {Errors}",
|
||||
logger.LogWarning("Failed to transfer files from {FolderPath} to bucket {DestinationBucketName}, key {DestinationKeyName}. Errors: {Errors}",
|
||||
folderPath,
|
||||
executeContext.Arguments.DestinationBucketName,
|
||||
executeContext.Arguments.DestinationKeyName,
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
|
||||
if (playList is null)
|
||||
{
|
||||
logger.LogError("PlayList with id {PlayListId} not found",
|
||||
logger.LogWarning("PlayList with id {PlayListId} not found",
|
||||
executeContext.Arguments.PlayListId);
|
||||
throw new InvalidOperationException($"PlayList with id {executeContext.Arguments.PlayListId} not found");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
|
||||
if (track is null)
|
||||
{
|
||||
logger.LogError("Track with id {TrackId} not found",
|
||||
logger.LogWarning("Track with id {TrackId} not found",
|
||||
executeContext.Arguments.TrackId);
|
||||
throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found");
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Musify.Infrastructure.Pictures
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogDebug("Resizing picture to {Width}x{Height}", width, height);
|
||||
if (pictureStream.CanSeek && pictureStream.Position > 0)
|
||||
pictureStream.Position = 0;
|
||||
|
||||
@@ -34,11 +35,12 @@ namespace Musify.Infrastructure.Pictures
|
||||
|
||||
memoryStream.Position = 0;
|
||||
|
||||
logger.LogDebug("Picture resized successfully. OutputLength: {Length}", memoryStream.Length);
|
||||
return Result<Stream>.Success(memoryStream);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "An error occurred while resizing the picture.");
|
||||
logger.LogError(exception, "An error occurred while resizing the picture to {Width}x{Height}.", width, height);
|
||||
return Result.Error("An error occurred while resizing the picture.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Musify.Infrastructure.Storage
|
||||
Key = keyName,
|
||||
};
|
||||
|
||||
logger.LogDebug("Getting file from S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogDebug("Getting file from S3. Bucket: {BucketName}, Key: {KeyName}", bucketName, keyName);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace Musify.Infrastructure.Storage
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogDebug(exception, "Failed to get file from S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogWarning(exception, "Failed to get file from S3. Bucket: {BucketName}, Key: {KeyName}", bucketName, keyName);
|
||||
return Result.NotFound($"File not found in S3 with bucket name {bucketName} and key name {keyName}");
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Musify.Infrastructure.Storage
|
||||
Protocol = storageClientConfiguration.UseHttp ? Protocol.HTTP : Protocol.HTTPS
|
||||
};
|
||||
|
||||
logger.LogDebug("Getting pre-signed URL from S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogDebug("Getting pre-signed URL from S3. Bucket: {BucketName}, Key: {KeyName}, Expires: {Expires}", bucketName, keyName, request.Expires);
|
||||
var url = await amazonS3.GetPreSignedURLAsync(request);
|
||||
|
||||
return url;
|
||||
@@ -60,7 +60,7 @@ namespace Musify.Infrastructure.Storage
|
||||
Key = keyName,
|
||||
};
|
||||
|
||||
logger.LogDebug("Removing file from S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogDebug("Removing file from S3. Bucket: {BucketName}, Key: {KeyName}", bucketName, keyName);
|
||||
var response = await amazonS3.DeleteObjectAsync(request, cancellationToken);
|
||||
|
||||
return Result.NoContent();
|
||||
@@ -72,6 +72,9 @@ namespace Musify.Infrastructure.Storage
|
||||
|
||||
var files = Directory.GetFiles(sourceDirectory, "*");
|
||||
|
||||
var successCount = 0;
|
||||
var failedCount = 0;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(file);
|
||||
@@ -90,17 +93,19 @@ namespace Musify.Infrastructure.Storage
|
||||
{
|
||||
await trasnsferUtility.UploadAsync(filePath, bucketName, fileName, cancellationToken);
|
||||
upload.State = UploadState.Successful;
|
||||
logger.LogInformation("Successfully transferred file {FileName} to S3 with bucket name {BucketName} and route {Route}", fileName, bucketName, route);
|
||||
successCount++;
|
||||
logger.LogDebug("Transferred file to S3. Bucket: {BucketName}, Route: {Route}, File: {FileName}", bucketName, route, fileName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to transfer file {FileName} to S3 with bucket name {BucketName} and route {Route}", fileName, bucketName, route);
|
||||
failedCount++;
|
||||
upload.State = UploadState.Failed;
|
||||
logger.LogError(exception, "Failed to transfer file to S3. Bucket: {BucketName}, Route: {Route}, File: {FileName}", bucketName, route, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
logger.LogInformation("Successfully saved upload records to database for all files transferred to S3 with bucket name {BucketName} and route {Route}", bucketName, route);
|
||||
logger.LogInformation("TransferFiles completed. Bucket: {BucketName}, Route: {Route}, Success: {SuccessCount}, Failed: {FailedCount}", bucketName, route, successCount, failedCount);
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
@@ -127,7 +132,7 @@ namespace Musify.Infrastructure.Storage
|
||||
try
|
||||
{
|
||||
var response = await amazonS3.PutObjectAsync(request, cancellationToken);
|
||||
logger.LogInformation("Successfully uploaded file to S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogDebug("Uploaded file to S3. Bucket: {BucketName}, Key: {KeyName}", bucketName, keyName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -138,7 +143,7 @@ namespace Musify.Infrastructure.Storage
|
||||
|
||||
upload.State = UploadState.Successful;
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
logger.LogInformation("Successfully saved upload record to database with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
|
||||
logger.LogDebug("Saved upload record to database. Bucket: {BucketName}, Key: {KeyName}", bucketName, keyName);
|
||||
|
||||
return Result.Success(keyName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user