2
0

ReloadLoggerFileTask.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, IConfigurableScheduledTask
  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 configuration manager.
  22. /// </summary>
  23. /// <value>The configuration manager.</value>
  24. private IConfigurationManager ConfigurationManager { get; set; }
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
  27. /// </summary>
  28. /// <param name="logManager">The logManager.</param>
  29. /// <param name="configurationManager">The configuration manager.</param>
  30. public ReloadLoggerFileTask(ILogManager logManager, IConfigurationManager configurationManager)
  31. {
  32. LogManager = logManager;
  33. ConfigurationManager = configurationManager;
  34. }
  35. /// <summary>
  36. /// Gets the default triggers.
  37. /// </summary>
  38. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  39. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  40. {
  41. var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(0) }; //12am
  42. return new[] { trigger };
  43. }
  44. /// <summary>
  45. /// Executes the internal.
  46. /// </summary>
  47. /// <param name="cancellationToken">The cancellation token.</param>
  48. /// <param name="progress">The progress.</param>
  49. /// <returns>Task.</returns>
  50. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  51. {
  52. cancellationToken.ThrowIfCancellationRequested();
  53. progress.Report(0);
  54. LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging
  55. ? LogSeverity.Debug
  56. : LogSeverity.Info);
  57. return Task.FromResult(true);
  58. }
  59. /// <summary>
  60. /// Gets the name.
  61. /// </summary>
  62. /// <value>The name.</value>
  63. public string Name
  64. {
  65. get { return "Start new log file"; }
  66. }
  67. /// <summary>
  68. /// Gets the description.
  69. /// </summary>
  70. /// <value>The description.</value>
  71. public string Description
  72. {
  73. get { return "Moves logging to a new file to help reduce log file sizes."; }
  74. }
  75. /// <summary>
  76. /// Gets the category.
  77. /// </summary>
  78. /// <value>The category.</value>
  79. public string Category
  80. {
  81. get { return "Application"; }
  82. }
  83. public bool IsHidden
  84. {
  85. get { return true; }
  86. }
  87. public bool IsEnabled
  88. {
  89. get { return true; }
  90. }
  91. }
  92. }