mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
wiredup db logging.
This commit is contained in:
parent
1016edb05b
commit
af4063c3e2
@ -29,9 +29,7 @@ private CommandResource RunCommand(CommandResource resource)
|
||||
.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 @@ public static class JsonExtensions
|
||||
}
|
||||
|
||||
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.Frontend;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using TinyIoC;
|
||||
|
||||
@ -29,6 +30,8 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline
|
||||
_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 @@ public static class PathExtensions
|
||||
{
|
||||
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 @@ public static string GetNzbDroneDatabase(this IEnvironmentProvider environmentPr
|
||||
{
|
||||
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;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using NzbDrone.Common;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
@ -21,12 +20,17 @@ public void Register()
|
||||
{
|
||||
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.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 @@ private void InitDatabase()
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user