diff --git a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs index 2e17aad44..68201d62c 100644 --- a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs +++ b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs @@ -1,6 +1,6 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using NLog; -using NLog.Fluent; namespace NzbDrone.Common.Instrumentation.Extensions { @@ -8,47 +8,46 @@ namespace NzbDrone.Common.Instrumentation.Extensions { 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..84658cf74 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneFileTarget.cs @@ -1,13 +1,15 @@ -using NLog; +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 750ad659c..3f5145c17 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs @@ -34,6 +34,8 @@ namespace NzbDrone.Common.Instrumentation var appFolderInfo = new AppFolderInfo(startupContext); + RegisterGlobalFilters(); + if (Debugger.IsAttached) { RegisterDebugger(); @@ -196,6 +198,17 @@ namespace NzbDrone.Common.Instrumentation LogManager.Configuration.LoggingRules.Insert(0, rule); } + private static void RegisterGlobalFilters() + { + LogManager.Setup().LoadConfiguration(c => + { + c.ForLogger("System.*").WriteToNil(LogLevel.Warn); + c.ForLogger("Microsoft.*").WriteToNil(LogLevel.Warn); + c.ForLogger("Microsoft.Hosting.Lifetime*").WriteToNil(LogLevel.Info); + c.ForLogger("Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware").WriteToNil(LogLevel.Fatal); + }); + } + public static Logger GetLogger(Type obj) { return LogManager.GetLogger(obj.Name.Replace("NzbDrone.", "")); diff --git a/src/NzbDrone.Common/Sonarr.Common.csproj b/src/NzbDrone.Common/Sonarr.Common.csproj index afd914994..6a55e3b5e 100644 --- a/src/NzbDrone.Common/Sonarr.Common.csproj +++ b/src/NzbDrone.Common/Sonarr.Common.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index d22589c37..a71c6b9cf 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using NLog; -using NLog.Fluent; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation.Extensions; @@ -247,14 +246,14 @@ namespace NzbDrone.Core.Download } else { - _logger.Debug() + _logger.ForDebugEvent() .Message("No Episodes were just imported, but all episodes were previously imported, possible issue with download history.") .Property("SeriesId", trackedDownload.RemoteEpisode.Series.Id) .Property("DownloadId", trackedDownload.DownloadItem.DownloadId) .Property("Title", trackedDownload.DownloadItem.Title) .Property("Path", trackedDownload.ImportItem.OutputPath.ToString()) .WriteSentryWarn("DownloadHistoryIncomplete") - .Write(); + .Log(); } var episodes = _episodeService.GetEpisodes(trackedDownload.RemoteEpisode.Episodes.Select(e => e.Id)); diff --git a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index 64a23782e..181e60278 100644 --- a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -33,22 +33,25 @@ namespace NzbDrone.Core.Instrumentation LogManager.Configuration.AddTarget("DbLogger", target); LogManager.Configuration.LoggingRules.Add(Rule); - LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded; + LogManager.ConfigurationChanged += OnLogManagerOnConfigurationReloaded; LogManager.ReconfigExistingLoggers(); } public void UnRegister() { - LogManager.ConfigurationReloaded -= OnLogManagerOnConfigurationReloaded; + LogManager.ConfigurationChanged -= OnLogManagerOnConfigurationReloaded; LogManager.Configuration.RemoveTarget("DbLogger"); LogManager.Configuration.LoggingRules.Remove(Rule); LogManager.ReconfigExistingLoggers(); Dispose(); } - private void OnLogManagerOnConfigurationReloaded(object sender, LoggingConfigurationReloadedEventArgs args) + private void OnLogManagerOnConfigurationReloaded(object sender, LoggingConfigurationChangedEventArgs args) { - Register(); + if (args.ActivatedConfiguration != null) + { + Register(); + } } public LoggingRule Rule { get; set; } diff --git a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs index d4b44eaa6..08cb4ca60 100644 --- a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs +++ b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Instrumentation syslogTarget.MessageSend.Protocol = ProtocolType.Udp; syslogTarget.MessageSend.Udp.Port = syslogPort; syslogTarget.MessageSend.Udp.Server = syslogServer; - syslogTarget.MessageSend.Udp.ReconnectInterval = 500; + syslogTarget.MessageSend.Retry.ConstantBackoff.BaseDelay = 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 154d25b7b..be89a95e4 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs @@ -2,7 +2,6 @@ using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using NLog; -using NLog.Fluent; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation.Extensions; @@ -153,10 +152,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo return "WMA"; } - Logger.Debug() + Logger.ForDebugEvent() .Message("Unknown audio format: '{0}' in '{1}'. Streams: {2}", audioFormat, sceneName, mediaInfo.RawStreamData) .WriteSentryWarn("UnknownAudioFormatFFProbe", mediaInfo.ContainerFormat, mediaInfo.AudioFormat, audioCodecID) - .Write(); + .Log(); return mediaInfo.AudioFormat; } @@ -268,10 +267,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo return ""; } - Logger.Debug() + Logger.ForDebugEvent() .Message("Unknown video format: '{0}' in '{1}'. Streams: {2}", videoFormat, sceneName, mediaInfo.RawStreamData) .WriteSentryWarn("UnknownVideoFormatFFProbe", mediaInfo.ContainerFormat, videoFormat, videoCodecID) - .Write(); + .Log(); return result; } diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index a07cfaebc..99045915e 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NLog.Fluent; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.DataAugmentation.Scene; @@ -386,24 +385,24 @@ namespace NzbDrone.Core.Parser if (tvdbId > 0 && tvdbId == searchCriteria.Series.TvdbId) { - _logger.Debug() + _logger.ForDebugEvent() .Message("Found matching series by TVDB ID {0}, an alias may be needed for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) .Property("TvdbId", tvdbId) .Property("ParsedEpisodeInfo", parsedEpisodeInfo) .WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) - .Write(); + .Log(); return new FindSeriesResult(searchCriteria.Series, SeriesMatchType.Id); } if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId && tvdbId <= 0) { - _logger.Debug() + _logger.ForDebugEvent() .Message("Found matching series by TVRage ID {0}, an alias may be needed for: {1}", tvRageId, parsedEpisodeInfo.SeriesTitle) .Property("TvRageId", tvRageId) .Property("ParsedEpisodeInfo", parsedEpisodeInfo) .WriteSentryWarn("TvRageIdMatch", tvRageId.ToString(), parsedEpisodeInfo.SeriesTitle) - .Write(); + .Log(); return new FindSeriesResult(searchCriteria.Series, SeriesMatchType.Id); } @@ -435,12 +434,12 @@ namespace NzbDrone.Core.Parser if (series != null) { - _logger.Debug() + _logger.ForDebugEvent() .Message("Found matching series by TVDB ID {0}, an alias may be needed for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) .Property("TvdbId", tvdbId) .Property("ParsedEpisodeInfo", parsedEpisodeInfo) .WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) - .Write(); + .Log(); matchType = SeriesMatchType.Id; } @@ -452,12 +451,12 @@ namespace NzbDrone.Core.Parser if (series != null) { - _logger.Debug() + _logger.ForDebugEvent() .Message("Found matching series by TVRage ID {0}, an alias may be needed for: {1}", tvRageId, parsedEpisodeInfo.SeriesTitle) .Property("TvRageId", tvRageId) .Property("ParsedEpisodeInfo", parsedEpisodeInfo) .WriteSentryWarn("TvRageIdMatch", tvRageId.ToString(), parsedEpisodeInfo.SeriesTitle) - .Write(); + .Log(); matchType = SeriesMatchType.Id; } diff --git a/src/NzbDrone.Core/Sonarr.Core.csproj b/src/NzbDrone.Core/Sonarr.Core.csproj index b5de0b05f..dd25a7184 100644 --- a/src/NzbDrone.Core/Sonarr.Core.csproj +++ b/src/NzbDrone.Core/Sonarr.Core.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/NzbDrone.Host/Sonarr.Host.csproj b/src/NzbDrone.Host/Sonarr.Host.csproj index 7eb3a4058..c2b82e95c 100644 --- a/src/NzbDrone.Host/Sonarr.Host.csproj +++ b/src/NzbDrone.Host/Sonarr.Host.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index b010e8e2c..f26a8fcf9 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -49,8 +49,8 @@ namespace NzbDrone.Host services.AddLogging(b => { b.ClearProviders(); - b.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); - b.AddFilter("Microsoft.AspNetCore", Microsoft.Extensions.Logging.LogLevel.Warning); + b.SetMinimumLevel(LogLevel.Trace); + b.AddFilter("Microsoft.AspNetCore", LogLevel.Warning); b.AddFilter("Sonarr.Http.Authentication", LogLevel.Information); b.AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", LogLevel.Error); b.AddNLog(); diff --git a/src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj b/src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj index bc5f721f6..4155803b2 100644 --- a/src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj +++ b/src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/NzbDrone.Update/Sonarr.Update.csproj b/src/NzbDrone.Update/Sonarr.Update.csproj index 624151093..4d07b3d1a 100644 --- a/src/NzbDrone.Update/Sonarr.Update.csproj +++ b/src/NzbDrone.Update/Sonarr.Update.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/NzbDrone.Windows/Sonarr.Windows.csproj b/src/NzbDrone.Windows/Sonarr.Windows.csproj index 96ab6ac02..e534a2b3f 100644 --- a/src/NzbDrone.Windows/Sonarr.Windows.csproj +++ b/src/NzbDrone.Windows/Sonarr.Windows.csproj @@ -4,7 +4,7 @@ true - + diff --git a/src/Sonarr.Api.V3/Sonarr.Api.V3.csproj b/src/Sonarr.Api.V3/Sonarr.Api.V3.csproj index 659783773..ac6900d33 100644 --- a/src/Sonarr.Api.V3/Sonarr.Api.V3.csproj +++ b/src/Sonarr.Api.V3/Sonarr.Api.V3.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Sonarr.Http/Sonarr.Http.csproj b/src/Sonarr.Http/Sonarr.Http.csproj index 6c0adc7d8..290357a96 100644 --- a/src/Sonarr.Http/Sonarr.Http.csproj +++ b/src/Sonarr.Http/Sonarr.Http.csproj @@ -5,7 +5,7 @@ - +