ReloadLoggerFileTask.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.Model.Tasks;
  8. namespace Emby.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<TaskTriggerInfo> GetDefaultTriggers()
  40. {
  41. var trigger = new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(0).Ticks }; //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. public string Key { get; }
  68. /// <summary>
  69. /// Gets the description.
  70. /// </summary>
  71. /// <value>The description.</value>
  72. public string Description
  73. {
  74. get { return "Moves logging to a new file to help reduce log file sizes."; }
  75. }
  76. /// <summary>
  77. /// Gets the category.
  78. /// </summary>
  79. /// <value>The category.</value>
  80. public string Category
  81. {
  82. get { return "Application"; }
  83. }
  84. public bool IsHidden
  85. {
  86. get { return true; }
  87. }
  88. public bool IsEnabled
  89. {
  90. get { return true; }
  91. }
  92. public bool IsLogged
  93. {
  94. get { return true; }
  95. }
  96. }
  97. }