wiredup db logging.

pull/3113/head
kay.one 11 years ago
parent 1016edb05b
commit af4063c3e2

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

@ -16,11 +16,17 @@ namespace NzbDrone.Api.Extensions
}
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);
body.Position = 0;
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)

@ -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<DatabaseTarget>().Register();
container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent());
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException);

@ -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);
}
}
}

@ -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();

@ -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<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>());
});
}
}
}
Loading…
Cancel
Save