ReloadLoggerTask.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 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. return Task.Run(() => LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info));
  55. }
  56. /// <summary>
  57. /// Gets the name.
  58. /// </summary>
  59. /// <value>The name.</value>
  60. public string Name
  61. {
  62. get { return "Start new log file"; }
  63. }
  64. /// <summary>
  65. /// Gets the description.
  66. /// </summary>
  67. /// <value>The description.</value>
  68. public string Description
  69. {
  70. get { return "Moves logging to a new file to help reduce log file sizes."; }
  71. }
  72. /// <summary>
  73. /// Gets the category.
  74. /// </summary>
  75. /// <value>The category.</value>
  76. public string Category
  77. {
  78. get { return "Application"; }
  79. }
  80. }
  81. }