From a59928c66a55d29e0741f92fc552db780a2d8d8f Mon Sep 17 00:00:00 2001 From: Robin Dadswell <19610103+RobinDadswell@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:26:59 +0100 Subject: [PATCH] Updated NLog Version (#7365) [common] --- .../Extensions/SentryLoggerExtensions.cs | 31 ++++++++++--------- .../Instrumentation/NzbDroneFileTarget.cs | 9 ++++-- .../Instrumentation/NzbDroneLogger.cs | 13 ++++++++ src/NzbDrone.Common/Radarr.Common.csproj | 6 ++-- .../Download/CompletedDownloadService.cs | 4 +-- .../Instrumentation/ReconfigureLogging.cs | 3 +- .../MediaInfo/MediaInfoFormatter.cs | 8 ++--- src/NzbDrone.Core/Radarr.Core.csproj | 2 +- .../Radarr.Test.Common.csproj | 2 +- src/NzbDrone.Update/Radarr.Update.csproj | 2 +- src/NzbDrone.Windows/Radarr.Windows.csproj | 2 +- src/Radarr.Api.V3/Radarr.Api.V3.csproj | 2 +- src/Radarr.Http/Radarr.Http.csproj | 2 +- 13 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs index 2e17aad44..437288d69 100644 --- a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs +++ b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using NLog; using NLog.Fluent; @@ -8,47 +10,46 @@ public static class SentryLoggerExtensions { public static readonly Logger SentryLogger = LogManager.GetLogger("Sentry"); - public static LogBuilder SentryFingerprint(this LogBuilder logBuilder, params string[] fingerprint) + public static LogEventBuilder SentryFingerprint(this LogEventBuilder logBuilder, params string[] fingerprint) { return logBuilder.Property("Sentry", fingerprint); } - public static LogBuilder WriteSentryDebug(this LogBuilder logBuilder, params string[] fingerprint) + public static LogEventBuilder WriteSentryDebug(this LogEventBuilder logBuilder, params string[] fingerprint) { return LogSentryMessage(logBuilder, LogLevel.Debug, fingerprint); } - public static LogBuilder WriteSentryInfo(this LogBuilder logBuilder, params string[] fingerprint) + public static LogEventBuilder WriteSentryInfo(this LogEventBuilder logBuilder, params string[] fingerprint) { return LogSentryMessage(logBuilder, LogLevel.Info, fingerprint); } - public static LogBuilder WriteSentryWarn(this LogBuilder logBuilder, params string[] fingerprint) + public static LogEventBuilder WriteSentryWarn(this LogEventBuilder logBuilder, params string[] fingerprint) { return LogSentryMessage(logBuilder, LogLevel.Warn, fingerprint); } - public static LogBuilder WriteSentryError(this LogBuilder logBuilder, params string[] fingerprint) + public static LogEventBuilder WriteSentryError(this LogEventBuilder logBuilder, params string[] fingerprint) { return LogSentryMessage(logBuilder, LogLevel.Error, fingerprint); } - private static LogBuilder LogSentryMessage(LogBuilder logBuilder, LogLevel level, string[] fingerprint) + private static LogEventBuilder LogSentryMessage(LogEventBuilder logBuilder, LogLevel level, string[] fingerprint) { - SentryLogger.Log(level) - .CopyLogEvent(logBuilder.LogEventInfo) + SentryLogger.ForLogEvent(level) + .CopyLogEvent(logBuilder.LogEvent) .SentryFingerprint(fingerprint) - .Write(); + .Log(); - return logBuilder.Property("Sentry", null); + return logBuilder.Property("Sentry", null); } - private static LogBuilder CopyLogEvent(this LogBuilder logBuilder, LogEventInfo logEvent) + private static LogEventBuilder CopyLogEvent(this LogEventBuilder logBuilder, LogEventInfo logEvent) { - return logBuilder.LoggerName(logEvent.LoggerName) - .TimeStamp(logEvent.TimeStamp) + return logBuilder.TimeStamp(logEvent.TimeStamp) .Message(logEvent.Message, logEvent.Parameters) - .Properties(logEvent.Properties.ToDictionary(v => v.Key, v => v.Value)) + .Properties(logEvent.Properties.Select(p => new KeyValuePair(p.Key.ToString(), p.Value))) .Exception(logEvent.Exception); } } diff --git a/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs b/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs index 62e41b0e0..e2c38f95c 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs @@ -1,13 +1,16 @@ -using NLog; +using System; +using System.Text; +using NLog; using NLog.Targets; namespace NzbDrone.Common.Instrumentation { public class NzbDroneFileTarget : FileTarget { - protected override string GetFormattedMessage(LogEventInfo logEvent) + protected override void RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target) { - return CleanseLogMessage.Cleanse(Layout.Render(logEvent)); + var result = CleanseLogMessage.Cleanse(Layout.Render(logEvent)); + target.Append(result); } } } diff --git a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs index 8f448ed28..8a8f296d3 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs @@ -34,6 +34,8 @@ public static void Register(IStartupContext startupContext, bool updateApp, bool var appFolderInfo = new AppFolderInfo(startupContext); + RegisterGlobalFilters(); + if (Debugger.IsAttached) { RegisterDebugger(); @@ -97,10 +99,21 @@ private static void RegisterDebugger() target.Layout = "[${level}] [${threadid}] ${logger}: ${message} ${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}${exception:format=Data}${newline}}"; var loggingRule = new LoggingRule("*", LogLevel.Trace, target); + LogManager.Configuration.AddTarget("debugger", target); LogManager.Configuration.LoggingRules.Add(loggingRule); } + private static void RegisterGlobalFilters() + { + LogManager.Setup().LoadConfiguration(c => + { + c.ForLogger("Microsoft.Hosting.Lifetime*").WriteToNil(LogLevel.Info); + c.ForLogger("System*").WriteToNil(LogLevel.Warn); + c.ForLogger("Microsoft*").WriteToNil(LogLevel.Warn); + }); + } + private static void RegisterConsole() { var level = LogLevel.Trace; diff --git a/src/NzbDrone.Common/Radarr.Common.csproj b/src/NzbDrone.Common/Radarr.Common.csproj index d0e40213c..40e59ad81 100644 --- a/src/NzbDrone.Common/Radarr.Common.csproj +++ b/src/NzbDrone.Common/Radarr.Common.csproj @@ -8,10 +8,10 @@ - - + + - + diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index df5d503e3..cd2433172 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -180,14 +180,14 @@ public bool VerifyImport(TrackedDownload trackedDownload, List imp } else { - _logger.Debug() + _logger.ForDebugEvent() .Message("No Movies were just imported, but all movies were previously imported, possible issue with download history.") .Property("MovieId", trackedDownload.RemoteMovie.Movie.Id) .Property("DownloadId", trackedDownload.DownloadItem.DownloadId) .Property("Title", trackedDownload.DownloadItem.Title) .Property("Path", trackedDownload.ImportItem.OutputPath.ToString()) .WriteSentryWarn("DownloadHistoryIncomplete") - .Write(); + .Log(); } trackedDownload.State = TrackedDownloadState.Imported; diff --git a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs index b2f80d8d1..38b695ccc 100644 --- a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs +++ b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using NLog; using NLog.Config; @@ -117,7 +117,6 @@ private void SetSyslogParameters(string syslogServer, int syslogPort, LogLevel m syslogTarget.MessageSend.Protocol = ProtocolType.Udp; syslogTarget.MessageSend.Udp.Port = syslogPort; syslogTarget.MessageSend.Udp.Server = syslogServer; - syslogTarget.MessageSend.Udp.ReconnectInterval = 500; syslogTarget.MessageCreation.Rfc = RfcNumber.Rfc5424; syslogTarget.MessageCreation.Rfc5424.AppName = _configFileProvider.InstanceName; diff --git a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs index 7b5e38d27..47c4c1326 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs @@ -153,10 +153,10 @@ public static string FormatAudioCodec(MediaInfoModel mediaInfo, string sceneName return "WMA"; } - Logger.Debug() + Logger.ForDebugEvent() .Message("Unknown audio format: '{0}' in '{1}'.", mediaInfo.RawStreamData, sceneName) .WriteSentryWarn("UnknownAudioFormatFFProbe", mediaInfo.ContainerFormat, mediaInfo.AudioFormat, audioCodecID) - .Write(); + .Log(); return mediaInfo.AudioFormat; } @@ -262,10 +262,10 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName return ""; } - Logger.Debug() + Logger.ForDebugEvent() .Message("Unknown video format: '{0}' in '{1}'.", mediaInfo.RawStreamData, sceneName) .WriteSentryWarn("UnknownVideoFormatFFProbe", mediaInfo.ContainerFormat, videoFormat, videoCodecID) - .Write(); + .Log(); return result; } diff --git a/src/NzbDrone.Core/Radarr.Core.csproj b/src/NzbDrone.Core/Radarr.Core.csproj index b4c1e9bdc..830aac966 100644 --- a/src/NzbDrone.Core/Radarr.Core.csproj +++ b/src/NzbDrone.Core/Radarr.Core.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/NzbDrone.Test.Common/Radarr.Test.Common.csproj b/src/NzbDrone.Test.Common/Radarr.Test.Common.csproj index 4ff7fed27..4a8f14b62 100644 --- a/src/NzbDrone.Test.Common/Radarr.Test.Common.csproj +++ b/src/NzbDrone.Test.Common/Radarr.Test.Common.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/NzbDrone.Update/Radarr.Update.csproj b/src/NzbDrone.Update/Radarr.Update.csproj index 17fb8d867..c0526a01c 100644 --- a/src/NzbDrone.Update/Radarr.Update.csproj +++ b/src/NzbDrone.Update/Radarr.Update.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/NzbDrone.Windows/Radarr.Windows.csproj b/src/NzbDrone.Windows/Radarr.Windows.csproj index 89b0e3ba0..4cc5baca4 100644 --- a/src/NzbDrone.Windows/Radarr.Windows.csproj +++ b/src/NzbDrone.Windows/Radarr.Windows.csproj @@ -4,7 +4,7 @@ true - + diff --git a/src/Radarr.Api.V3/Radarr.Api.V3.csproj b/src/Radarr.Api.V3/Radarr.Api.V3.csproj index f3bf67994..44e8380fb 100644 --- a/src/Radarr.Api.V3/Radarr.Api.V3.csproj +++ b/src/Radarr.Api.V3/Radarr.Api.V3.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Radarr.Http/Radarr.Http.csproj b/src/Radarr.Http/Radarr.Http.csproj index 0f0160eed..098bf3a28 100644 --- a/src/Radarr.Http/Radarr.Http.csproj +++ b/src/Radarr.Http/Radarr.Http.csproj @@ -5,7 +5,7 @@ - +