using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
///
/// Class ReloadLoggerFileTask
///
public class ReloadLoggerFileTask : IScheduledTask
{
///
/// Gets or sets the log manager.
///
/// The log manager.
private ILogManager LogManager { get; set; }
///
/// Gets or sets the logger.
///
/// The logger.
private ILogger Logger { get; set; }
///
/// Gets or sets the kernel.
///
/// The kernel.
private IKernel Kernel { get; set; }
///
/// Initializes a new instance of the class.
///
/// The logManager.
/// The logger.
/// The kernel.
public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IKernel kernel)
{
LogManager = logManager;
Logger = logger;
Kernel = kernel;
}
///
/// Gets the default triggers.
///
/// IEnumerable{BaseTaskTrigger}.
public IEnumerable GetDefaultTriggers()
{
var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(0) }; //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 Task.Run(() => LogManager.ReloadLogger(Kernel.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info));
}
///
/// Gets the name.
///
/// The name.
public string Name
{
get { return "Start new log file"; }
}
///
/// 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"; }
}
}
}