Change LoggingSettings.MaxLogAge from integer (minutes) to a TimeSpan.

This commit is contained in:
Andy Butland
2020-10-31 14:25:40 +01:00
parent 88380a17ae
commit 433fdbb047
3 changed files with 9 additions and 25 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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>();