fix saving the log level

pull/193/head
Drewster727 9 years ago
parent 5dc39b9b3a
commit 84edd6636d

@ -83,6 +83,7 @@
<Compile Include="SettingModels\PushBulletNotificationSettings.cs" /> <Compile Include="SettingModels\PushBulletNotificationSettings.cs" />
<Compile Include="SettingModels\EmailNotificationSettings.cs" /> <Compile Include="SettingModels\EmailNotificationSettings.cs" />
<Compile Include="SettingModels\PlexSettings.cs" /> <Compile Include="SettingModels\PlexSettings.cs" />
<Compile Include="SettingModels\LogSettings.cs" />
<Compile Include="SettingModels\SonarrSettings.cs" /> <Compile Include="SettingModels\SonarrSettings.cs" />
<Compile Include="SettingModels\SickRageSettings.cs" /> <Compile Include="SettingModels\SickRageSettings.cs" />
<Compile Include="SettingModels\CouchPotatoSettings.cs" /> <Compile Include="SettingModels\CouchPotatoSettings.cs" />

@ -0,0 +1,36 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SickRageSettings.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using NLog;
namespace PlexRequests.Core.SettingModels
{
public class LogSettings : Settings
{
public int Level { get; set; }
}
}

@ -78,6 +78,7 @@ namespace PlexRequests.UI
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>(); container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>(); container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>();
container.Register<ISettingsService<HeadphonesSettings>, SettingsServiceV2<HeadphonesSettings>>(); container.Register<ISettingsService<HeadphonesSettings>, SettingsServiceV2<HeadphonesSettings>>();
container.Register<ISettingsService<LogSettings>, SettingsServiceV2<LogSettings>>();
// Repo's // Repo's
container.Register<IRepository<LogEntity>, GenericRepository<LogEntity>>(); container.Register<IRepository<LogEntity>, GenericRepository<LogEntity>>();

@ -68,6 +68,7 @@ namespace PlexRequests.UI.Modules
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; } private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
private ISettingsService<PushoverNotificationSettings> PushoverService { get; } private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
private ISettingsService<HeadphonesSettings> HeadphonesService { get; } private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
private ISettingsService<LogSettings> LogService { get; }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISonarrApi SonarrApi { get; } private ISonarrApi SonarrApi { get; }
private IPushbulletApi PushbulletApi { get; } private IPushbulletApi PushbulletApi { get; }
@ -95,6 +96,7 @@ namespace PlexRequests.UI.Modules
IRepository<LogEntity> logsRepo, IRepository<LogEntity> logsRepo,
INotificationService notify, INotificationService notify,
ISettingsService<HeadphonesSettings> headphones, ISettingsService<HeadphonesSettings> headphones,
ISettingsService<LogSettings> logs,
ICacheProvider cache) : base("admin") ICacheProvider cache) : base("admin")
{ {
PrService = prService; PrService = prService;
@ -114,6 +116,7 @@ namespace PlexRequests.UI.Modules
PushoverApi = pushoverApi; PushoverApi = pushoverApi;
NotificationService = notify; NotificationService = notify;
HeadphonesService = headphones; HeadphonesService = headphones;
LogService = logs;
Cache = cache; Cache = cache;
#if !DEBUG #if !DEBUG
@ -637,8 +640,16 @@ namespace PlexRequests.UI.Modules
private Response UpdateLogLevels(int level) private Response UpdateLogLevels(int level)
{ {
var settings = LogService.GetSettings();
// apply the level
var newLevel = LogLevel.FromOrdinal(level); var newLevel = LogLevel.FromOrdinal(level);
LoggingHelper.ReconfigureLogLevel(newLevel); LoggingHelper.ReconfigureLogLevel(newLevel);
//save the log settings
settings.Level = level;
LogService.SaveSettings(settings);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"}); return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"});
} }

@ -25,7 +25,6 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using Microsoft.Owin.Hosting; using Microsoft.Owin.Hosting;
@ -42,8 +41,6 @@ using PlexRequests.Store.Repository;
using System.Diagnostics; using System.Diagnostics;
using FluentScheduler; using FluentScheduler;
using PlexRequests.Services;
using PlexRequests.UI.Jobs; using PlexRequests.UI.Jobs;
namespace PlexRequests.UI namespace PlexRequests.UI
@ -91,6 +88,7 @@ namespace PlexRequests.UI
var cn = s.SetupDb(baseUrl); var cn = s.SetupDb(baseUrl);
s.CacheQualityProfiles(); s.CacheQualityProfiles();
ConfigureTargets(cn); ConfigureTargets(cn);
SetupLogging();
if (port == -1) if (port == -1)
port = GetStartupPort(); port = GetStartupPort();
@ -157,6 +155,17 @@ namespace PlexRequests.UI
LoggingHelper.ConfigureLogging(connectionString); LoggingHelper.ConfigureLogging(connectionString);
} }
private static void SetupLogging()
{
var settingsService = new SettingsServiceV2<LogSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var logSettings = settingsService.GetSettings();
if (logSettings != null)
{
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
}
}
private static void SetupSchedulers() private static void SetupSchedulers()
{ {
TaskManager.TaskFactory = new PlexTaskFactory(); TaskManager.TaskFactory = new PlexTaskFactory();

@ -76,11 +76,14 @@
url: logUrl, url: logUrl,
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
$("#select > option").each(function (level) { if (response && response.length > 0) {
if (response[0] == level.value) { $("#selected > option").each(function (level) {
$('#' + level.target.id).prop("selected", "selected"); var $opt = $(this);
if (response[0].ordinal == level) {
$opt.prop("selected", "selected");
} }
}); });
}
}, },
error: function (e) { error: function (e) {
console.log(e); console.log(e);

Loading…
Cancel
Save