From acfe320b8bd9f66a3196a10a75f5ed2959889188 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Sun, 11 Jun 2023 13:51:38 -0600 Subject: [PATCH] Add more logging. --- server/RdtClient.Service/Helpers/Logger.cs | 2 +- .../RdtClient.Service/Services/TorrentRunner.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/RdtClient.Service/Helpers/Logger.cs b/server/RdtClient.Service/Helpers/Logger.cs index ea3b503..7a27860 100644 --- a/server/RdtClient.Service/Helpers/Logger.cs +++ b/server/RdtClient.Service/Helpers/Logger.cs @@ -18,7 +18,7 @@ public static class Logger var done = (Int32)((Double)download.BytesDone / download.BytesTotal * 100); - return $"for download {fileName} {done}% ({download.DownloadId})"; + return $"for download {fileName}. Completed: {done}%, avg speed: {download.Speed}bytes/s ({download.DownloadId})"; } public static String ToLog(this Torrent torrent) diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 593629f..ae4f2c4 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -161,7 +161,7 @@ public class TorrentRunner if (!String.IsNullOrWhiteSpace(downloadClient.Error)) { // Retry the download if an error is encountered. - Log($"Download reported an error: {downloadClient.Error}", download, download.Torrent); + LogError($"Download reported an error: {downloadClient.Error}", download, download.Torrent); Log($"Download retry count {download.RetryCount}/{download.Torrent!.DownloadRetryAttempts}, torrent retry count {download.Torrent.RetryCount}/{download.Torrent.TorrentRetryAttempts}", download, download.Torrent); if (download.RetryCount < download.Torrent.DownloadRetryAttempts) @@ -613,4 +613,19 @@ public class TorrentRunner _logger.LogDebug(message); } + + private void LogError(String message, Download? download, Torrent? torrent) + { + if (download != null) + { + message = $"{message} {download.ToLog()}"; + } + + if (torrent != null) + { + message = $"{message} {torrent.ToLog()}"; + } + + _logger.LogError(message); + } } \ No newline at end of file