ReloadLoggerFileTask.cs 3.4 KB

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