From bceaee27a379bd81be43832b06180d8f84fa12a6 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 30 Aug 2013 18:42:30 -0700 Subject: [PATCH] moved logging config to in-process --- NzbDrone.Api/NancyBootstrapper.cs | 3 +- .../SignalR/BasicResourceConnection.cs | 3 +- NzbDrone.Common/DiskProvider.cs | 3 +- .../EnvironmentInfo/AppFolderInfo.cs | 3 +- .../EnvironmentInfo/RuntimeInfo.cs | 1 - .../EnvironmentInfo/StartupArguments.cs | 12 -- .../ApplicationLogLayoutRenderer.cs | 26 ---- .../DirSeparatorLayoutRenderer.cs | 19 --- .../Instrumentation/ExceptronTarget.cs | 10 -- .../GlobalExceptionHandlers.cs | 5 +- NzbDrone.Common/Instrumentation/LogTargets.cs | 138 ++++++++++++++++++ .../Instrumentation/LogglyTarget.cs | 11 +- .../Instrumentation/NzbDroneLogger.cs | 42 ++++++ .../UpdateLogLayoutRenderer.cs | 28 ---- NzbDrone.Common/NzbDrone.Common.csproj | 5 +- NzbDrone.Common/ProcessProvider.cs | 3 +- .../Security/IgnoreCertErrorPolicy.cs | 3 +- NzbDrone.Common/ServiceProvider.cs | 3 +- NzbDrone.Common/TPL/TaskExtensions.cs | 3 +- NzbDrone.Console/ConsoleApp.cs | 9 +- .../DatabaseTargetFixture.cs | 4 +- .../Download/Clients/PneumaticClient.cs | 3 +- .../Sabnzbd/SabAutoConfigureService.cs | 3 +- NzbDrone.Core/Indexers/BasicRssParser.cs | 3 +- .../Indexers/NzbClub/NzbClubParser.cs | 3 +- NzbDrone.Core/Indexers/XElementExtensions.cs | 3 +- .../MediaFiles/RecycleBinProvider.cs | 3 +- .../Notifications/Growl/GrowlService.cs | 3 +- .../Notifications/Xbmc/XbmcService.cs | 3 +- NzbDrone.Core/Parser/Parser.cs | 3 +- .../Providers/XemCommunicationProvider.cs | 3 +- NzbDrone.Core/Providers/XemProvider.cs | 3 +- NzbDrone.Core/Rest/RestSharpExtensions.cs | 5 +- .../RootFolders/RootFolderService.cs | 3 +- NzbDrone.Core/Tv/EpisodeService.cs | 3 +- NzbDrone.Host/Bootstrap.cs | 2 +- NzbDrone.Host/NLog.config | 31 ---- NzbDrone.Host/NzbDrone.Host.csproj | 4 - NzbDrone.Host/Owin/NlogTextWriter.cs | 3 +- NzbDrone.Host/PlatformValidation.cs | 3 +- NzbDrone.Update/NLog.config | 17 --- NzbDrone.Update/NzbDrone.Update.csproj | 4 - NzbDrone.Update/UpdateApp.cs | 8 +- NzbDrone/WindowsApp.cs | 10 +- 44 files changed, 257 insertions(+), 203 deletions(-) delete mode 100644 NzbDrone.Common/Instrumentation/ApplicationLogLayoutRenderer.cs delete mode 100644 NzbDrone.Common/Instrumentation/DirSeparatorLayoutRenderer.cs create mode 100644 NzbDrone.Common/Instrumentation/LogTargets.cs create mode 100644 NzbDrone.Common/Instrumentation/NzbDroneLogger.cs delete mode 100644 NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs delete mode 100644 NzbDrone.Host/NLog.config delete mode 100644 NzbDrone.Update/NLog.config diff --git a/NzbDrone.Api/NancyBootstrapper.cs b/NzbDrone.Api/NancyBootstrapper.cs index 5f65c80e2..4e481119a 100644 --- a/NzbDrone.Api/NancyBootstrapper.cs +++ b/NzbDrone.Api/NancyBootstrapper.cs @@ -6,6 +6,7 @@ using NzbDrone.Api.Authentication; using NzbDrone.Api.ErrorManagement; using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions.Pipelines; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Lifecycle; @@ -21,7 +22,7 @@ namespace NzbDrone.Api public NancyBootstrapper(TinyIoCContainer tinyIoCContainer) { _tinyIoCContainer = tinyIoCContainer; - _logger = LogManager.GetCurrentClassLogger(); + _logger = NzbDroneLogger.GetLogger(); } protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) diff --git a/NzbDrone.Api/SignalR/BasicResourceConnection.cs b/NzbDrone.Api/SignalR/BasicResourceConnection.cs index e56ae4fd2..4166b07cb 100644 --- a/NzbDrone.Api/SignalR/BasicResourceConnection.cs +++ b/NzbDrone.Api/SignalR/BasicResourceConnection.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Infrastructure; using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Events; @@ -18,7 +19,7 @@ namespace NzbDrone.Api.SignalR public BasicResourceConnection() { - _logger = LogManager.GetCurrentClassLogger(); + _logger = NzbDroneLogger.GetLogger(this); } protected override Task OnConnected(IRequest request, string connectionId) diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index 851ba4550..592a7d12c 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -8,6 +8,7 @@ using System.Security.Principal; using NLog; using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common { @@ -58,7 +59,7 @@ namespace NzbDrone.Common out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public HashSet SpecialFolders { diff --git a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs index e93395756..04f7b29ab 100644 --- a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs +++ b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs @@ -4,6 +4,7 @@ using System.Reflection; using System.Security.AccessControl; using System.Security.Principal; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common.EnvironmentInfo { @@ -30,7 +31,7 @@ namespace NzbDrone.Common.EnvironmentInfo DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData; } - _logger = LogManager.GetCurrentClassLogger(); + _logger = NzbDroneLogger.GetLogger(this); if (startupArguments.Args.ContainsKey(StartupArguments.APPDATA)) { diff --git a/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs b/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs index 7bd6e8d3c..f2d0e4caf 100644 --- a/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs +++ b/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.IO; using System.Security.Principal; -using System.ServiceProcess; using NLog; namespace NzbDrone.Common.EnvironmentInfo diff --git a/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs b/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs index 9075d64e0..5aeb9c351 100644 --- a/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs +++ b/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs @@ -17,14 +17,6 @@ namespace NzbDrone.Common.EnvironmentInfo public const string UNINSTALL_SERVICE = "u"; public const string HELP = "?"; - static StartupArguments() - { - if (RuntimeInfo.IsProduction) - { - Instance = new StartupArguments(""); - } - } - public StartupArguments(params string[] args) { Flags = new HashSet(); @@ -45,13 +37,9 @@ namespace NzbDrone.Common.EnvironmentInfo Flags.Add(flag); } } - - Instance = this; } public HashSet Flags { get; private set; } public Dictionary Args { get; private set; } - - public static IStartupArguments Instance { get; private set; } } } \ No newline at end of file diff --git a/NzbDrone.Common/Instrumentation/ApplicationLogLayoutRenderer.cs b/NzbDrone.Common/Instrumentation/ApplicationLogLayoutRenderer.cs deleted file mode 100644 index 2a2082d18..000000000 --- a/NzbDrone.Common/Instrumentation/ApplicationLogLayoutRenderer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.IO; -using System.Text; -using NLog; -using NLog.Config; -using NLog.LayoutRenderers; -using NzbDrone.Common.EnvironmentInfo; - -namespace NzbDrone.Common.Instrumentation -{ - [ThreadAgnostic] - [LayoutRenderer("appLog")] - public class ApplicationLogLayoutRenderer : LayoutRenderer - { - private readonly string _appData; - - public ApplicationLogLayoutRenderer() - { - _appData = Path.Combine(new AppFolderInfo(new DiskProvider(), StartupArguments.Instance ).GetLogFolder(), "nzbdrone.txt"); - } - - protected override void Append(StringBuilder builder, LogEventInfo logEvent) - { - builder.Append(_appData); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Instrumentation/DirSeparatorLayoutRenderer.cs b/NzbDrone.Common/Instrumentation/DirSeparatorLayoutRenderer.cs deleted file mode 100644 index bb5658326..000000000 --- a/NzbDrone.Common/Instrumentation/DirSeparatorLayoutRenderer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.IO; -using System.Text; -using NLog; -using NLog.Config; -using NLog.LayoutRenderers; - -namespace NzbDrone.Common.Instrumentation -{ - [ThreadAgnostic] - [LayoutRenderer("dirSeparator")] - public class DirSeparatorLayoutRenderer : LayoutRenderer - { - - protected override void Append(StringBuilder builder, LogEventInfo logEvent) - { - builder.Append(Path.DirectorySeparatorChar); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Instrumentation/ExceptronTarget.cs b/NzbDrone.Common/Instrumentation/ExceptronTarget.cs index 59ff5e918..89208be7a 100644 --- a/NzbDrone.Common/Instrumentation/ExceptronTarget.cs +++ b/NzbDrone.Common/Instrumentation/ExceptronTarget.cs @@ -24,17 +24,7 @@ namespace NzbDrone.Common.Instrumentation public IExceptronClient ExceptronClient { get; internal set; } - private static ExceptronTarget _instance = new ExceptronTarget(); - public static void Register() - { - var rule = new LoggingRule("*", LogLevel.Warn, _instance); - - LogManager.Configuration.AddTarget("ExceptronTarget", _instance); - LogManager.Configuration.LoggingRules.Add(rule); - LogManager.ConfigurationReloaded += (sender, args) => Register(); - LogManager.ReconfigExistingLoggers(); - } protected override void InitializeTarget() { diff --git a/NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs b/NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs index 24fb64c61..20a076b58 100644 --- a/NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs +++ b/NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs @@ -6,12 +6,9 @@ namespace NzbDrone.Common.Instrumentation { public static class GlobalExceptionHandlers { - private static readonly Logger Logger = LogManager.GetLogger("Global"); - + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static void Register() { - ExceptronTarget.Register(); - AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception)); TaskScheduler.UnobservedTaskException += ((s, e) => TaskException(e.Exception)); } diff --git a/NzbDrone.Common/Instrumentation/LogTargets.cs b/NzbDrone.Common/Instrumentation/LogTargets.cs new file mode 100644 index 000000000..1e0e3f419 --- /dev/null +++ b/NzbDrone.Common/Instrumentation/LogTargets.cs @@ -0,0 +1,138 @@ +using System; +using System.IO; +using NLog; +using NLog.Config; +using NLog.Targets; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Common.Instrumentation +{ + public static class LogTargets + { + public static void Register(IStartupArguments startupArguments, bool updateApp, bool inConsole) + { + var appFolderInfo = new AppFolderInfo(new DiskProvider(), startupArguments); + + LogManager.Configuration = new LoggingConfiguration(); + + RegisterExceptron(); + + if (updateApp) + { + RegisterLoggly(); + RegisterUpdateFile(appFolderInfo); + } + else + { + if (inConsole && (OsInfo.IsLinux || new RuntimeInfo(null).IsUserInteractive)) + { + RegisterConsole(); + } + + RegisterAppFile(appFolderInfo); + } + } + + private static void RegisterConsole() + { + var level = LogLevel.Trace; + + if (RuntimeInfo.IsProduction) + { + level = LogLevel.Info; + } + + var coloredConsoleTarget = new ColoredConsoleTarget(); + + coloredConsoleTarget.Name = "consoleLogger"; + coloredConsoleTarget.Layout = "[${level}] ${logger}: ${message} ${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"; + + var loggingRule = new LoggingRule("*", level, coloredConsoleTarget); + + LogManager.Configuration.AddTarget("console", coloredConsoleTarget); + LogManager.Configuration.LoggingRules.Add(loggingRule); + + LogManager.ConfigurationReloaded += (sender, args) => RegisterConsole(); + LogManager.ReconfigExistingLoggers(); + } + + + const string FileLogLayout = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"; + + private static void RegisterAppFile(IAppFolderInfo appFolderInfo) + { + var fileTarget = new FileTarget(); + + fileTarget.Name = "rollingFileLogger"; + fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), "nzbdrone.txt"); + fileTarget.AutoFlush = true; + fileTarget.KeepFileOpen = false; + fileTarget.ConcurrentWrites = false; + fileTarget.ConcurrentWriteAttemptDelay = 50; + fileTarget.ConcurrentWriteAttempts = 10; + fileTarget.ArchiveAboveSize = 1024000; + fileTarget.MaxArchiveFiles = 5; + fileTarget.EnableFileDelete = true; + fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling; + fileTarget.Layout = FileLogLayout; + + var loggingRule = new LoggingRule("*", LogLevel.Info, fileTarget); + + LogManager.Configuration.AddTarget("appfile", fileTarget); + LogManager.Configuration.LoggingRules.Add(loggingRule); + + LogManager.ConfigurationReloaded += (sender, args) => RegisterAppFile(appFolderInfo); + LogManager.ReconfigExistingLoggers(); + } + + + + private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo) + { + var fileTarget = new FileTarget(); + + fileTarget.Name = "updateFileLogger"; + fileTarget.FileName = Path.Combine(appFolderInfo.GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt"); + fileTarget.AutoFlush = true; + fileTarget.KeepFileOpen = false; + fileTarget.ConcurrentWrites = false; + fileTarget.ConcurrentWriteAttemptDelay = 50; + fileTarget.ConcurrentWriteAttempts = 100; + fileTarget.Layout = FileLogLayout; + + var loggingRule = new LoggingRule("*", LogLevel.Trace, fileTarget); + + LogManager.Configuration.AddTarget("updateFile", fileTarget); + LogManager.Configuration.LoggingRules.Add(loggingRule); + + LogManager.ConfigurationReloaded += (sender, args) => RegisterUpdateFile(appFolderInfo); + LogManager.ReconfigExistingLoggers(); + } + + private static void RegisterExceptron() + { + + var exceptronTarget = new ExceptronTarget(); + var rule = new LoggingRule("*", LogLevel.Warn, exceptronTarget); + + LogManager.Configuration.AddTarget("ExceptronTarget", exceptronTarget); + LogManager.Configuration.LoggingRules.Add(rule); + LogManager.ConfigurationReloaded += (sender, args) => RegisterExceptron(); + LogManager.ReconfigExistingLoggers(); + } + + + public static void RegisterLoggly() + { + var logglyTarger = new LogglyTarget(); + + var rule = new LoggingRule("*", LogLevel.Trace, logglyTarger); + + LogManager.Configuration.AddTarget("LogglyLogger", logglyTarger); + LogManager.Configuration.LoggingRules.Add(rule); + LogManager.ConfigurationReloaded += (sender, args) => RegisterLoggly(); + LogManager.ReconfigExistingLoggers(); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Common/Instrumentation/LogglyTarget.cs b/NzbDrone.Common/Instrumentation/LogglyTarget.cs index 33d953390..8f2817581 100644 --- a/NzbDrone.Common/Instrumentation/LogglyTarget.cs +++ b/NzbDrone.Common/Instrumentation/LogglyTarget.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using NLog; -using NLog.Config; using NLog.Layouts; using NLog.Targets; using NzbDrone.Common.EnvironmentInfo; @@ -13,16 +12,10 @@ namespace NzbDrone.Common.Instrumentation { private Logger _logger; - public void Register(LogLevel minLevel) + public LogglyTarget() { Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}"); - - var rule = new LoggingRule("*", minLevel, this); - - LogManager.Configuration.AddTarget("LogglyLogger", this); - LogManager.Configuration.LoggingRules.Add(rule); - LogManager.ConfigurationReloaded += (sender, args) => Register(minLevel); - LogManager.ReconfigExistingLoggers(); + } protected override void InitializeTarget() diff --git a/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs b/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs new file mode 100644 index 000000000..c722d5160 --- /dev/null +++ b/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs @@ -0,0 +1,42 @@ +using System; +using System.Diagnostics; +using NLog; + +namespace NzbDrone.Common.Instrumentation +{ + public static class NzbDroneLogger + { + public static Logger GetLogger() + { + string loggerName; + Type declaringType; + int framesToSkip = 1; + do + { + var frame = new StackFrame(framesToSkip, false); + var method = frame.GetMethod(); + declaringType = method.DeclaringType; + if (declaringType == null) + { + loggerName = method.Name; + break; + } + + framesToSkip++; + loggerName = declaringType.Name; + } while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase)); + + return LogManager.GetLogger(loggerName); + } + + public static Logger GetLogger(object obj) + { + return LogManager.GetLogger(obj.GetType().Name); + } + + public static Logger GetLogger() + { + return LogManager.GetLogger(typeof(T).Name); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs b/NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs deleted file mode 100644 index 2f55d36de..000000000 --- a/NzbDrone.Common/Instrumentation/UpdateLogLayoutRenderer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.IO; -using System.Text; -using NLog; -using NLog.Config; -using NLog.LayoutRenderers; -using NzbDrone.Common.EnvironmentInfo; - -namespace NzbDrone.Common.Instrumentation -{ - [ThreadAgnostic] - [LayoutRenderer("updateLog")] - public class UpdateLogLayoutRenderer : LayoutRenderer - { - private readonly string _appData; - - public UpdateLogLayoutRenderer() - { - _appData = Path.Combine(new AppFolderInfo(new DiskProvider(), StartupArguments.Instance).GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt"); - - } - - protected override void Append(StringBuilder builder, LogEventInfo logEvent) - { - builder.Append(_appData); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index c1b17236f..d379a7a3a 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -92,6 +92,8 @@ + + @@ -99,11 +101,8 @@ - - - diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 8df4198e8..ffb647709 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Model; namespace NzbDrone.Common @@ -26,7 +27,7 @@ namespace NzbDrone.Common public class ProcessProvider : IProcessProvider { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public const string NZB_DRONE_PROCESS_NAME = "NzbDrone"; public const string NZB_DRONE_CONSOLE_PROCESS_NAME = "NzbDrone.Console"; diff --git a/NzbDrone.Common/Security/IgnoreCertErrorPolicy.cs b/NzbDrone.Common/Security/IgnoreCertErrorPolicy.cs index 1be964380..809b0fe74 100644 --- a/NzbDrone.Common/Security/IgnoreCertErrorPolicy.cs +++ b/NzbDrone.Common/Security/IgnoreCertErrorPolicy.cs @@ -3,12 +3,13 @@ using System.Net.Security; using System.Security.Cryptography.X509Certificates; using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common.Security { public static class IgnoreCertErrorPolicy { - private static readonly Logger Logger = LogManager.GetLogger("CertPolicy"); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static void Register() { diff --git a/NzbDrone.Common/ServiceProvider.cs b/NzbDrone.Common/ServiceProvider.cs index 7287e36df..8c2206a63 100644 --- a/NzbDrone.Common/ServiceProvider.cs +++ b/NzbDrone.Common/ServiceProvider.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Linq; using System.ServiceProcess; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common { @@ -25,7 +26,7 @@ namespace NzbDrone.Common { public const string NZBDRONE_SERVICE_NAME = "NzbDrone"; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public virtual bool ServiceExist(string name) { diff --git a/NzbDrone.Common/TPL/TaskExtensions.cs b/NzbDrone.Common/TPL/TaskExtensions.cs index e655ac86f..855ae225c 100644 --- a/NzbDrone.Common/TPL/TaskExtensions.cs +++ b/NzbDrone.Common/TPL/TaskExtensions.cs @@ -1,11 +1,12 @@ using System.Threading.Tasks; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common.TPL { public static class TaskExtensions { - private static readonly Logger Logger = LogManager.GetLogger("TaskExtensions"); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static Task LogExceptions(this Task task) { diff --git a/NzbDrone.Console/ConsoleApp.cs b/NzbDrone.Console/ConsoleApp.cs index 3119cc811..8b633510d 100644 --- a/NzbDrone.Console/ConsoleApp.cs +++ b/NzbDrone.Console/ConsoleApp.cs @@ -2,17 +2,22 @@ using System.Threading; using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; using NzbDrone.Host; namespace NzbDrone.Console { public static class ConsoleApp { + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); + public static void Main(string[] args) { try { - Bootstrap.Start(new StartupArguments(args), new ConsoleAlerts()); + var startupArgs = new StartupArguments(args); + LogTargets.Register(startupArgs, false, true); + Bootstrap.Start(startupArgs, new ConsoleAlerts()); } catch (TerminateApplicationException) { @@ -28,4 +33,4 @@ namespace NzbDrone.Console } } } -} \ No newline at end of file +} diff --git a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs index 6bb9644a9..22784f95b 100644 --- a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs +++ b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using FluentAssertions; using NLog; using NUnit.Framework; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Instrumentation; @@ -36,8 +37,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests LogManager.ReconfigExistingLoggers(); - _logger = LogManager.GetCurrentClassLogger(); - _loggerName = _logger.Name.Replace("NzbDrone.",""); + _logger = NzbDroneLogger.GetLogger(); _uniqueMessage = "Unique message: " + Guid.NewGuid().ToString(); } diff --git a/NzbDrone.Core/Download/Clients/PneumaticClient.cs b/NzbDrone.Core/Download/Clients/PneumaticClient.cs index a7e59b6a4..ff4929805 100644 --- a/NzbDrone.Core/Download/Clients/PneumaticClient.cs +++ b/NzbDrone.Core/Download/Clients/PneumaticClient.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Configuration; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; @@ -15,7 +16,7 @@ namespace NzbDrone.Core.Download.Clients private readonly IHttpProvider _httpProvider; private readonly IDiskProvider _diskProvider; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = NzbDroneLogger.GetLogger(); public PneumaticClient(IConfigService configService, IHttpProvider httpProvider, IDiskProvider diskProvider) diff --git a/NzbDrone.Core/Download/Clients/Sabnzbd/SabAutoConfigureService.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/SabAutoConfigureService.cs index 6ff5a666a..224cae5c5 100644 --- a/NzbDrone.Core/Download/Clients/Sabnzbd/SabAutoConfigureService.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/SabAutoConfigureService.cs @@ -6,12 +6,13 @@ using System.Net; using System.Net.NetworkInformation; using System.Text.RegularExpressions; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Core.Download.Clients.Sabnzbd { public class SabAutoConfigureService { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public SabModel AutoConfigureSab() { diff --git a/NzbDrone.Core/Indexers/BasicRssParser.cs b/NzbDrone.Core/Indexers/BasicRssParser.cs index 84c61f296..447a27674 100644 --- a/NzbDrone.Core/Indexers/BasicRssParser.cs +++ b/NzbDrone.Core/Indexers/BasicRssParser.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers @@ -22,7 +23,7 @@ namespace NzbDrone.Core.Indexers public BasicRssParser() { - _logger = LogManager.GetCurrentClassLogger(); + _logger = NzbDroneLogger.GetLogger(this); } public IEnumerable Process(string xml, string url) diff --git a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs index 9c17b0ffa..30a3b899e 100644 --- a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs +++ b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.NzbClub @@ -15,7 +16,7 @@ namespace NzbDrone.Core.Indexers.NzbClub public NzbClubParser() { - logger = LogManager.GetCurrentClassLogger(); + logger = NzbDroneLogger.GetLogger(); } diff --git a/NzbDrone.Core/Indexers/XElementExtensions.cs b/NzbDrone.Core/Indexers/XElementExtensions.cs index 8460c34d6..1608d0ec6 100644 --- a/NzbDrone.Core/Indexers/XElementExtensions.cs +++ b/NzbDrone.Core/Indexers/XElementExtensions.cs @@ -5,13 +5,14 @@ using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Core.Indexers { public static class XElementExtensions { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); private static readonly Regex RemoveTimeZoneRegex = new Regex(@"\s[A-Z]{2,4}$", RegexOptions.Compiled); diff --git a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index ff3866b39..17f286c71 100644 --- a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -3,6 +3,7 @@ using System.IO; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.Commands; @@ -23,7 +24,7 @@ namespace NzbDrone.Core.MediaFiles private readonly IDiskProvider _diskProvider; private readonly IConfigService _configService; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = NzbDroneLogger.GetLogger(); public RecycleBinProvider(IDiskProvider diskProvider, IConfigService configService) { diff --git a/NzbDrone.Core/Notifications/Growl/GrowlService.cs b/NzbDrone.Core/Notifications/Growl/GrowlService.cs index deed4b369..e99a9d8dc 100644 --- a/NzbDrone.Core/Notifications/Growl/GrowlService.cs +++ b/NzbDrone.Core/Notifications/Growl/GrowlService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Growl.Connector; using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using GrowlNotification = Growl.Connector.Notification; @@ -15,7 +16,7 @@ namespace NzbDrone.Core.Notifications.Growl public class GrowlService : IGrowlService, IExecute { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); private readonly Application _growlApplication = new Application("NzbDrone"); private GrowlConnector _growlConnector; diff --git a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index cc0f9bf3c..6df04e75b 100644 --- a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -5,6 +5,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Xbmc; @@ -21,7 +22,7 @@ namespace NzbDrone.Core.Notifications.Xbmc public class XbmcService : IXbmcService, IExecute { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); private readonly IHttpProvider _httpProvider; private readonly IEnumerable _apiProviders; diff --git a/NzbDrone.Core/Parser/Parser.cs b/NzbDrone.Core/Parser/Parser.cs index 3178b5084..4863e6b3a 100644 --- a/NzbDrone.Core/Parser/Parser.cs +++ b/NzbDrone.Core/Parser/Parser.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; @@ -13,7 +14,7 @@ namespace NzbDrone.Core.Parser { public static class Parser { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); private static readonly Regex[] ReportTitleRegex = new[] { diff --git a/NzbDrone.Core/Providers/XemCommunicationProvider.cs b/NzbDrone.Core/Providers/XemCommunicationProvider.cs index 803b74e65..5c0e07132 100644 --- a/NzbDrone.Core/Providers/XemCommunicationProvider.cs +++ b/NzbDrone.Core/Providers/XemCommunicationProvider.cs @@ -5,6 +5,7 @@ using NLog; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NzbDrone.Common; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Model.Xem; namespace NzbDrone.Core.Providers @@ -20,7 +21,7 @@ namespace NzbDrone.Core.Providers { private readonly IHttpProvider _httpProvider; - private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger _logger = NzbDroneLogger.GetLogger(); private const string XEM_BASE_URL = "http://thexem.de/map/"; diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 931793dfb..d2abb6776 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Cache; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Tv; @@ -25,7 +26,7 @@ namespace NzbDrone.Core.Providers private readonly ISeriesService _seriesService; private readonly ICached _cache; - private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger _logger = NzbDroneLogger.GetLogger(); public XemProvider(IEpisodeService episodeService, IXemCommunicationProvider xemCommunicationProvider, diff --git a/NzbDrone.Core/Rest/RestSharpExtensions.cs b/NzbDrone.Core/Rest/RestSharpExtensions.cs index b0c09368c..33b5e681b 100644 --- a/NzbDrone.Core/Rest/RestSharpExtensions.cs +++ b/NzbDrone.Core/Rest/RestSharpExtensions.cs @@ -1,6 +1,7 @@ using System.Net; using NLog; using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Serializer; using RestSharp; @@ -8,7 +9,7 @@ namespace NzbDrone.Core.Rest { public static class RestSharpExtensions { - private static readonly Logger Logger = LogManager.GetLogger("RestExtensions"); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static IRestResponse ValidateResponse(this IRestResponse response, IRestClient restClient) { @@ -22,7 +23,7 @@ namespace NzbDrone.Core.Rest Ensure.That(() => response.Request).IsNotNull(); Ensure.That(() => restClient).IsNotNull(); - Logger.Trace("Validating Responses from [{0}] [{1}] status: [{2}] body:[{3}]", response.Request.Method, restClient.BuildUri(response.Request), response.StatusCode, response.Content); + Logger.Trace("Validating Responses from [{0}] [{1}] status: [{2}]", response.Request.Method, restClient.BuildUri(response.Request), response.StatusCode); if (response.ResponseUri == null) { diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 160cd3c9f..7360f898c 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Tv; @@ -23,7 +24,7 @@ namespace NzbDrone.Core.RootFolders public class RootFolderService : IRootFolderService { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); private readonly IBasicRepository _rootFolderRepository; private readonly IDiskProvider _diskProvider; private readonly ISeriesRepository _seriesRepository; diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index dce584fa4..7747510d8 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; @@ -40,7 +41,7 @@ namespace NzbDrone.Core.Tv IHandleAsync { - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = NzbDroneLogger.GetLogger(); private readonly IEpisodeRepository _episodeRepository; private readonly IConfigService _configService; diff --git a/NzbDrone.Host/Bootstrap.cs b/NzbDrone.Host/Bootstrap.cs index e4b592fd1..7f108f799 100644 --- a/NzbDrone.Host/Bootstrap.cs +++ b/NzbDrone.Host/Bootstrap.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Host { public static IContainer Start(StartupArguments args, IUserAlert userAlert) { - var logger = LogManager.GetLogger("AppMain"); + var logger = NzbDroneLogger.GetLogger(); GlobalExceptionHandlers.Register(); IgnoreCertErrorPolicy.Register(); diff --git a/NzbDrone.Host/NLog.config b/NzbDrone.Host/NLog.config deleted file mode 100644 index 65103a066..000000000 --- a/NzbDrone.Host/NLog.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - Exception - ${exception:format=ToString} - - - - - - - - - - \ No newline at end of file diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj index c625626ea..49c4850bd 100644 --- a/NzbDrone.Host/NzbDrone.Host.csproj +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -141,10 +141,6 @@ - - Always - Designer - Designer diff --git a/NzbDrone.Host/Owin/NlogTextWriter.cs b/NzbDrone.Host/Owin/NlogTextWriter.cs index d4cd4da7d..fb912893f 100644 --- a/NzbDrone.Host/Owin/NlogTextWriter.cs +++ b/NzbDrone.Host/Owin/NlogTextWriter.cs @@ -1,12 +1,13 @@ using System.IO; using System.Text; using NLog; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Host.Owin { public class NlogTextWriter : TextWriter { - private readonly Logger logger = LogManager.GetCurrentClassLogger(); + private readonly Logger logger = NzbDroneLogger.GetLogger(); public override Encoding Encoding diff --git a/NzbDrone.Host/PlatformValidation.cs b/NzbDrone.Host/PlatformValidation.cs index 978a579ae..703918aca 100644 --- a/NzbDrone.Host/PlatformValidation.cs +++ b/NzbDrone.Host/PlatformValidation.cs @@ -3,12 +3,13 @@ using System.Diagnostics; using System.Reflection; using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Host { public static class PlatformValidation { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static bool IsValidate(IUserAlert userAlert) { diff --git a/NzbDrone.Update/NLog.config b/NzbDrone.Update/NLog.config deleted file mode 100644 index 8398980c9..000000000 --- a/NzbDrone.Update/NLog.config +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NzbDrone.Update/NzbDrone.Update.csproj b/NzbDrone.Update/NzbDrone.Update.csproj index c2d12c5c4..a1d42c2e0 100644 --- a/NzbDrone.Update/NzbDrone.Update.csproj +++ b/NzbDrone.Update/NzbDrone.Update.csproj @@ -63,10 +63,6 @@ - - Always - Designer - Designer diff --git a/NzbDrone.Update/UpdateApp.cs b/NzbDrone.Update/UpdateApp.cs index 167499373..3a882cd74 100644 --- a/NzbDrone.Update/UpdateApp.cs +++ b/NzbDrone.Update/UpdateApp.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Update private readonly IProcessProvider _processProvider; private static IContainer _container; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = NzbDroneLogger.GetLogger(); public UpdateApp(IInstallUpdateService installUpdateService, IProcessProvider processProvider) { @@ -28,14 +28,16 @@ namespace NzbDrone.Update { try { + var startupArgument = new StartupArguments(args); + LogTargets.Register(startupArgument, true, true); + Console.WriteLine("Starting NzbDrone Update Client"); IgnoreCertErrorPolicy.Register(); GlobalExceptionHandlers.Register(); - new LogglyTarget().Register(LogLevel.Trace); - _container = UpdateContainerBuilder.Build(new StartupArguments(args)); + _container = UpdateContainerBuilder.Build(startupArgument); logger.Info("Updating NzbDrone to version {0}", BuildInfo.Version); _container.Resolve().Start(args); diff --git a/NzbDrone/WindowsApp.cs b/NzbDrone/WindowsApp.cs index 4d4dc9d69..dd96cf596 100644 --- a/NzbDrone/WindowsApp.cs +++ b/NzbDrone/WindowsApp.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Instrumentation; using NzbDrone.Host; using NzbDrone.SysTray; @@ -9,12 +10,17 @@ namespace NzbDrone { public static class WindowsApp { + private static readonly Logger Logger = NzbDroneLogger.GetLogger(); public static void Main(string[] args) { try { - var container = Bootstrap.Start(new StartupArguments(args), new MessageBoxUserAlert()); + var startupArgs = new StartupArguments(args); + + LogTargets.Register(startupArgs, false, true); + + var container = Bootstrap.Start(startupArgs, new MessageBoxUserAlert()); container.Register(); container.Resolve().Start(); } @@ -28,4 +34,4 @@ namespace NzbDrone } } } -} \ No newline at end of file +}