1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

wiredup db logging.

This commit is contained in:
kay.one 2013-05-20 20:20:29 -07:00
parent 1016edb05b
commit af4063c3e2
6 changed files with 31 additions and 6 deletions

View File

@ -29,9 +29,7 @@ private CommandResource RunCommand(CommandResource resource)
.Single(c => c.Name.Replace("Command", "") .Single(c => c.Name.Replace("Command", "")
.Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase)); .Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase));
dynamic command = Request.Body.FromJson(commandType);
var command = Request.Body.FromJson<ICommand>(commandType);
_messageAggregator.PublishCommand(command); _messageAggregator.PublishCommand(command);
return resource; return resource;

View File

@ -16,11 +16,17 @@ public static class JsonExtensions
} }
public static T FromJson<T>(this Stream body, Type type) public static T FromJson<T>(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); var reader = new StreamReader(body, true);
body.Position = 0; body.Position = 0;
var value = reader.ReadToEnd(); var value = reader.ReadToEnd();
return (T)Json.Deserialize(value, type); return Json.Deserialize(value, type);
} }
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK) public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)

View File

@ -7,6 +7,7 @@
using NzbDrone.Api.Frontend; using NzbDrone.Api.Frontend;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using TinyIoC; using TinyIoC;
@ -29,6 +30,8 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline
_logger.Info("Starting NzbDrone API"); _logger.Info("Starting NzbDrone API");
AutomapperBootstraper.InitializeAutomapper(); AutomapperBootstraper.InitializeAutomapper();
container.Resolve<DatabaseTarget>().Register();
container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent()); container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent());
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException); ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException);

View File

@ -7,6 +7,7 @@ public static class PathExtensions
{ {
private static readonly string APP_CONFIG_FILE = "config.xml"; private static readonly string APP_CONFIG_FILE = "config.xml";
private static readonly string NZBDRONE_DB = "nzbdrone.db"; 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 BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar; private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar;
@ -113,5 +114,10 @@ public static string GetNzbDroneDatabase(this IEnvironmentProvider environmentPr
{ {
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB); return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB);
} }
public static string GetLogDatabase(this IEnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_LOG_DB);
}
} }
} }

View File

@ -3,7 +3,6 @@
using NLog; using NLog;
using NLog.Layouts; using NLog.Layouts;
using NLog.Targets; using NLog.Targets;
using NzbDrone.Common;
namespace NzbDrone.Core.Instrumentation namespace NzbDrone.Core.Instrumentation
{ {
@ -21,12 +20,17 @@ public void Register()
{ {
Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}"); 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.AddTarget("DbLogger", this);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, this)); LogManager.Configuration.LoggingRules.Add(Rule);
LogManager.ConfigurationReloaded += (sender, args) => Register(); LogManager.ConfigurationReloaded += (sender, args) => Register();
LogManager.ReconfigExistingLoggers();
} }
public LoggingRule Rule { get; set; }
protected override void Write(LogEventInfo logEvent) protected override void Write(LogEventInfo logEvent)
{ {
var log = new Log(); var log = new Log();

View File

@ -5,7 +5,9 @@
using NzbDrone.Api.SignalR; using NzbDrone.Api.SignalR;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
@ -53,6 +55,12 @@ private void InitDatabase()
} }
Container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase())); Container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
Container.Register<ILogRepository>(c =>
{
var db = c.Resolve<IDbFactory>().Create(environmentProvider.GetLogDatabase(), MigrationType.Log);
return new LogRepository(db, c.Resolve<IMessageAggregator>());
});
} }
} }
} }