Change LoggingSettings.MaxLogAge from integer (minutes) to a TimeSpan.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
namespace Umbraco.Core.Configuration.Models
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Models
|
||||
{
|
||||
public class LoggingSettings
|
||||
{
|
||||
public int MaxLogAge { get; set; } = -1;
|
||||
public TimeSpan MaxLogAge { get; set; } = TimeSpan.FromHours(24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,28 +61,9 @@ namespace Umbraco.Infrastructure.HostedServices
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
using (_profilingLogger.DebugDuration<LogScrubber>("Log scrubbing executing", "Log scrubbing complete"))
|
||||
{
|
||||
_auditService.CleanLogs(GetLogScrubbingMaximumAgeInMinutes(_settings));
|
||||
_auditService.CleanLogs((int)_settings.MaxLogAge.TotalMinutes);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
private int GetLogScrubbingMaximumAgeInMinutes(LoggingSettings settings)
|
||||
{
|
||||
var maximumAge = 24 * 60; // 24 hours, in minutes
|
||||
try
|
||||
{
|
||||
if (settings.MaxLogAge > -1)
|
||||
{
|
||||
maximumAge = settings.MaxLogAge;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unable to locate a log scrubbing maximum age. Defaulting to 24 hours.");
|
||||
}
|
||||
|
||||
return maximumAge;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -44,7 +45,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Executes_And_Srubs_Logs()
|
||||
public void Executes_And_Scrubs_Logs()
|
||||
{
|
||||
var sut = CreateLogScrubber();
|
||||
sut.ExecuteAsync(null);
|
||||
@@ -57,7 +58,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
{
|
||||
var settings = new LoggingSettings
|
||||
{
|
||||
MaxLogAge = _maxLogAgeInMinutes,
|
||||
MaxLogAge = TimeSpan.FromMinutes(_maxLogAgeInMinutes),
|
||||
};
|
||||
|
||||
var mockServerRegistrar = new Mock<IServerRegistrar>();
|
||||
|
||||
Reference in New Issue
Block a user