using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Tasks; namespace Emby.Server.Implementations.ScheduledTasks.Tasks { /// /// Class ReloadLoggerFileTask /// public class ReloadLoggerFileTask : IScheduledTask, IConfigurableScheduledTask { /// /// Gets or sets the log manager. /// /// The log manager. private ILogManager LogManager { get; set; } /// /// Gets or sets the configuration manager. /// /// The configuration manager. private IConfigurationManager ConfigurationManager { get; set; } /// /// Initializes a new instance of the class. /// /// The logManager. /// The configuration manager. public ReloadLoggerFileTask(ILogManager logManager, IConfigurationManager configurationManager) { LogManager = logManager; ConfigurationManager = configurationManager; } /// /// Gets the default triggers. /// /// IEnumerable{BaseTaskTrigger}. public IEnumerable GetDefaultTriggers() { var trigger = new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(0).Ticks }; //12am return new[] { trigger }; } /// /// Executes the internal. /// /// The cancellation token. /// The progress. /// Task. public Task Execute(CancellationToken cancellationToken, IProgress progress) { cancellationToken.ThrowIfCancellationRequested(); progress.Report(0); return LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info, cancellationToken); } /// /// Gets the name. /// /// The name. public string Name { get { return "Rotate log file"; } } public string Key { get; } /// /// Gets the description. /// /// The description. public string Description { get { return "Moves logging to a new file to help reduce log file sizes."; } } /// /// Gets the category. /// /// The category. public string Category { get { return "Application"; } } public bool IsHidden { get { return false; } } public bool IsEnabled { get { return true; } } public bool IsLogged { get { return true; } } } }