ReloadLoggerTask.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.ScheduledTasks;
  3. using MediaBrowser.Model.Logging;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
  9. {
  10. /// <summary>
  11. /// Class ReloadLoggerFileTask
  12. /// </summary>
  13. public class ReloadLoggerFileTask : IScheduledTask
  14. {
  15. /// <summary>
  16. /// Gets or sets the log manager.
  17. /// </summary>
  18. /// <value>The log manager.</value>
  19. private ILogManager LogManager { get; set; }
  20. /// <summary>
  21. /// Gets or sets the logger.
  22. /// </summary>
  23. /// <value>The logger.</value>
  24. private ILogger Logger { get; set; }
  25. /// <summary>
  26. /// Gets or sets the configuration manager.
  27. /// </summary>
  28. /// <value>The configuration manager.</value>
  29. private IConfigurationManager ConfigurationManager { get; set; }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
  32. /// </summary>
  33. /// <param name="logManager">The logManager.</param>
  34. /// <param name="logger">The logger.</param>
  35. /// <param name="configurationManager">The configuration manager.</param>
  36. public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IConfigurationManager configurationManager)
  37. {
  38. LogManager = logManager;
  39. Logger = logger;
  40. ConfigurationManager = configurationManager;
  41. }
  42. /// <summary>
  43. /// Gets the default triggers.
  44. /// </summary>
  45. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  46. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  47. {
  48. var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(0) }; //12am
  49. return new[] { trigger };
  50. }
  51. /// <summary>
  52. /// Executes the internal.
  53. /// </summary>
  54. /// <param name="cancellationToken">The cancellation token.</param>
  55. /// <param name="progress">The progress.</param>
  56. /// <returns>Task.</returns>
  57. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  58. {
  59. cancellationToken.ThrowIfCancellationRequested();
  60. progress.Report(0);
  61. return Task.Run(() => LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info));
  62. }
  63. /// <summary>
  64. /// Gets the name.
  65. /// </summary>
  66. /// <value>The name.</value>
  67. public string Name
  68. {
  69. get { return "Start new log file"; }
  70. }
  71. /// <summary>
  72. /// Gets the description.
  73. /// </summary>
  74. /// <value>The description.</value>
  75. public string Description
  76. {
  77. get { return "Moves logging to a new file to help reduce log file sizes."; }
  78. }
  79. /// <summary>
  80. /// Gets the category.
  81. /// </summary>
  82. /// <value>The category.</value>
  83. public string Category
  84. {
  85. get { return "Application"; }
  86. }
  87. }
  88. }