diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index e80852a2f..b5d2c2c59 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -29,9 +29,7 @@ namespace NzbDrone.Api.Commands .Single(c => c.Name.Replace("Command", "") .Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase)); - - var command = Request.Body.FromJson(commandType); - + dynamic command = Request.Body.FromJson(commandType); _messageAggregator.PublishCommand(command); return resource; diff --git a/NzbDrone.Api/Extensions/RequestExtensions.cs b/NzbDrone.Api/Extensions/RequestExtensions.cs index e72fd86e7..17e3292b0 100644 --- a/NzbDrone.Api/Extensions/RequestExtensions.cs +++ b/NzbDrone.Api/Extensions/RequestExtensions.cs @@ -16,11 +16,17 @@ namespace NzbDrone.Api.Extensions } public static T FromJson(this Stream body, Type type) + { + return (T)FromJson(body, type); + } + + + public static object FromJson(this Stream body, Type type) { var reader = new StreamReader(body, true); body.Position = 0; var value = reader.ReadToEnd(); - return (T)Json.Deserialize(value, type); + return Json.Deserialize(value, type); } public static JsonResponse AsResponse(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK) diff --git a/NzbDrone.Api/NancyBootstrapper.cs b/NzbDrone.Api/NancyBootstrapper.cs index 0707f4bb2..f31528274 100644 --- a/NzbDrone.Api/NancyBootstrapper.cs +++ b/NzbDrone.Api/NancyBootstrapper.cs @@ -7,6 +7,7 @@ using NzbDrone.Api.Extensions; using NzbDrone.Api.Frontend; using NzbDrone.Common.Composition; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Lifecycle; using TinyIoC; @@ -29,6 +30,8 @@ namespace NzbDrone.Api _logger.Info("Starting NzbDrone API"); AutomapperBootstraper.InitializeAutomapper(); + container.Resolve().Register(); + container.Resolve().PublishEvent(new ApplicationStartedEvent()); ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve().HandleException); diff --git a/NzbDrone.Common/PathExtensions.cs b/NzbDrone.Common/PathExtensions.cs index b9eb70a53..4c320740b 100644 --- a/NzbDrone.Common/PathExtensions.cs +++ b/NzbDrone.Common/PathExtensions.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Common { private static readonly string APP_CONFIG_FILE = "config.xml"; private static readonly string NZBDRONE_DB = "nzbdrone.db"; + private static readonly string NZBDRONE_LOG_DB = "logs.db"; private static readonly string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip"; private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar; @@ -113,5 +114,10 @@ namespace NzbDrone.Common { return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB); } + + public static string GetLogDatabase(this IEnvironmentProvider environmentProvider) + { + return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_LOG_DB); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index 98c8c376b..b39a818b3 100644 --- a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -3,7 +3,6 @@ using NLog.Config; using NLog; using NLog.Layouts; using NLog.Targets; -using NzbDrone.Common; namespace NzbDrone.Core.Instrumentation { @@ -21,12 +20,17 @@ namespace NzbDrone.Core.Instrumentation { Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}"); + Rule = new LoggingRule("*", LogLevel.Debug, this); + LogManager.Configuration.AddTarget("DbLogger", this); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, this)); + LogManager.Configuration.LoggingRules.Add(Rule); LogManager.ConfigurationReloaded += (sender, args) => Register(); + LogManager.ReconfigExistingLoggers(); } + public LoggingRule Rule { get; set; } + protected override void Write(LogEventInfo logEvent) { var log = new Log(); diff --git a/NzbDrone/MainAppContainerBuilder.cs b/NzbDrone/MainAppContainerBuilder.cs index ab60ffd0a..82951d05f 100644 --- a/NzbDrone/MainAppContainerBuilder.cs +++ b/NzbDrone/MainAppContainerBuilder.cs @@ -5,7 +5,9 @@ using NzbDrone.Api; using NzbDrone.Api.SignalR; using NzbDrone.Common; using NzbDrone.Common.Composition; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Notifications; using NzbDrone.Core.Organizer; using NzbDrone.Core.RootFolders; @@ -53,6 +55,12 @@ namespace NzbDrone } Container.Register(c => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())); + + Container.Register(c => + { + var db = c.Resolve().Create(environmentProvider.GetLogDatabase(), MigrationType.Log); + return new LogRepository(db, c.Resolve()); + }); } } } \ No newline at end of file