Commit 863d390e authored by Alessio Parma's avatar Alessio Parma

log messages

parent 8c098830
......@@ -69,11 +69,11 @@ public async Task<JsonResult> OnPost(CancellationToken cancellationToken)
if (!recaptchaResponse.success)
{
_logger.LogWarning("Received an invalid reCAPTCHA token from host {HostName}, returning an invalid API key", recaptchaResponse.hostname);
_logger.LogWarning("Received an invalid reCAPTCHA token from host '{HostName}', returning an invalid API key", recaptchaResponse.hostname);
return new JsonResult(ApiKeyDTO.Invalid);
}
_logger.LogInformation("Received a valid reCAPTCHA token from host {HostName}, returning a valid temporary API key", recaptchaResponse.hostname);
_logger.LogInformation("Received a valid reCAPTCHA token from host '{HostName}', returning a valid temporary API key", recaptchaResponse.hostname);
return new JsonResult(await _apiKeyStore.AddTempApiKeyAsync(cancellationToken).ConfigureAwait(false));
}
}
......
......@@ -110,11 +110,11 @@ private async Task DeleteOldTempFilesAsync(CancellationToken stoppingToken)
if (File.GetLastAccessTimeUtc(file.Path) >= threshold)
{
_logger.LogDebug("File {FileName} has a last access time newer than {Threshold}, it will not be deleted", fileName, threshold);
_logger.LogDebug("File '{FileName}' has a last access time newer than {Threshold}, it will not be deleted", fileName, threshold);
continue;
}
_logger.LogDebug("File {FileName} has a last access time older than {Threshold}, it will be deleted", fileName, threshold);
_logger.LogDebug("File '{FileName}' has a last access time older than {Threshold}, it will be deleted", fileName, threshold);
File.Delete(file.Path);
deletedFileCount++;
......
......@@ -82,7 +82,7 @@ public sealed class SystemCommandManager : ICommandManager
command.Kill();
_logger.LogWarning("A timeout occurred while running {CommandName} with following arguments: {CommandArgs}. Configured timeout is: {Timeout}", realCommandName, commandArgs, timeout);
throw new CommandException($"External command \"{realCommandName}\" exceeded the timeout of {timeout} milliseconds and it was killed", realCommandName, command.ExitCode);
throw new CommandException($"External command {realCommandName} exceeded the timeout of {timeout} milliseconds and it was killed", realCommandName, command.ExitCode);
}
catch (InvalidOperationException)
{
......@@ -96,7 +96,7 @@ public sealed class SystemCommandManager : ICommandManager
var commandError = await command.StandardError.ReadToEndAsync().ConfigureAwait(false);
_logger.LogError("{CommandName} exited with code {ExitCode}. It was started with following arguments: {CommandArgs}. Command error is: {CommandError}", realCommandName, command.ExitCode, commandArgs, commandError);
throw new CommandException($"External command \"{realCommandName}\" raised an error", realCommandName, command.ExitCode);
throw new CommandException($"External command {realCommandName} raised an error", realCommandName, command.ExitCode);
}
}
}
......
......@@ -73,30 +73,31 @@ public void Dispose()
/// <inheritdoc/>
public async Task<TempFileDTO> DownloadFileAsync(Uri fileUri, CancellationToken cancellationToken)
{
_logger.LogDebug("Downloading file {FileUri}", fileUri);
_logger.LogDebug("Downloading file '{FileUri}'", fileUri);
using var response = await _httpClient.GetAsync(fileUri, cancellationToken).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
_logger.LogError("An error occurred while downloading file {FileUri}. Remote response status code was {ResponseStatusCode}", fileUri, response.StatusCode);
_logger.LogError("An error occurred while downloading file '{FileUri}'. Remote response status code was {ResponseStatusCode}", fileUri, response.StatusCode);
throw new InvalidOperationException($"File download failed, remote response status code was {response.StatusCode}");
}
var contentType = response.Content.Headers.ContentType.MediaType;
var extension = Path.GetExtension(response.Content.Headers.ContentDisposition?.FileName);
_logger.LogInformation("Handling download of file with content type {ContentType} and file extension {Extension}", contentType, extension);
var fileName = response.Content.Headers.ContentDisposition?.FileName;
var extension = Path.GetExtension(fileName);
_logger.LogInformation("Handling download of file with content type '{ContentType}', extension '{Extension}' and file name '{FileName}'", contentType, extension, fileName);
var file = new TempFileDTO(contentType, extension);
if (file.ContentType != contentType)
{
_logger.LogInformation("Content type of downloaded file has been overridden with {ContentType}", file.ContentType);
_logger.LogInformation("Content type of downloaded file has been overridden with '{ContentType}'", contentType);
}
_logger.LogInformation("File {FileUri} has {ContentType} content type", fileUri, file.ContentType);
_logger.LogInformation("File '{FileUri}' has '{ContentType}' content type", fileUri, contentType);
if (file.IsHtmlDocument)
{
_logger.LogDebug("File {FileUri} is an HTML file, it will not be downloaded", fileUri);
_logger.LogDebug("File '{FileUri}' is an HTML file, it will not be downloaded", fileUri);
// Following services will use file URI directly, in order to better interact with
// potentially external assets (CSS and JS files, images).
......@@ -105,7 +106,7 @@ public async Task<TempFileDTO> DownloadFileAsync(Uri fileUri, CancellationToken
}
file = await _tempFileStore.GetTempFileAsync(file.ContentType, cancellationToken).ConfigureAwait(false);
_logger.LogDebug("File {FileUri} downloaded successfully, it will be stored at path {FilePath}", fileUri, file.Path);
_logger.LogDebug("File '{FileUri}' downloaded successfully, it will be stored at path '{FilePath}'", fileUri, file.Path);
using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
using var fileStream = File.OpenWrite(file.Path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment