From f7acd57f73d5f4bc1637363a1f01f018e01d259b Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 19 Oct 2024 06:25:54 +0300 Subject: [PATCH] Cleanse exceptions in event logs (cherry picked from commit 404e6d68ea526ab521cd39ecda1bf3b02285765d) --- .../Instrumentation/DatabaseTarget.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index 75930ebe7..76b8b4e65 100644 --- a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -60,33 +60,36 @@ namespace NzbDrone.Core.Instrumentation { try { - var log = new Log(); - log.Time = logEvent.TimeStamp; - log.Message = CleanseLogMessage.Cleanse(logEvent.FormattedMessage); - - log.Logger = logEvent.LoggerName; + var log = new Log + { + Time = logEvent.TimeStamp, + Logger = logEvent.LoggerName, + Level = logEvent.Level.Name + }; if (log.Logger.StartsWith("NzbDrone.")) { log.Logger = log.Logger.Remove(0, 9); } + var message = logEvent.FormattedMessage; + if (logEvent.Exception != null) { - if (string.IsNullOrWhiteSpace(log.Message)) + if (string.IsNullOrWhiteSpace(message)) { - log.Message = logEvent.Exception.Message; + message = logEvent.Exception.Message; } else { - log.Message += ": " + logEvent.Exception.Message; + message += ": " + logEvent.Exception.Message; } - log.Exception = logEvent.Exception.ToString(); + log.Exception = CleanseLogMessage.Cleanse(logEvent.Exception.ToString()); log.ExceptionType = logEvent.Exception.GetType().ToString(); } - log.Level = logEvent.Level.Name; + log.Message = CleanseLogMessage.Cleanse(message); var connectionInfo = _connectionStringFactory.LogDbConnection;