Browse Source

Configure retention time for logs.

pull/469/head
Sebastian 6 years ago
parent
commit
3189969a3d
  1. 9
      backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs
  2. 14
      backend/src/Squidex.Infrastructure/Log/Store/RequestLogStoreOptions.cs
  3. 3
      backend/src/Squidex/Config/Domain/LoggingServices.cs
  4. 6
      backend/src/Squidex/appsettings.json

9
backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using MongoDB.Driver; using MongoDB.Driver;
using NodaTime; using NodaTime;
using Squidex.Infrastructure.Log.Store; using Squidex.Infrastructure.Log.Store;
@ -20,10 +21,14 @@ namespace Squidex.Infrastructure.Log
public sealed class MongoRequestLogRepository : MongoRepositoryBase<MongoRequest>, IRequestLogRepository public sealed class MongoRequestLogRepository : MongoRepositoryBase<MongoRequest>, IRequestLogRepository
{ {
private static readonly InsertManyOptions Unordered = new InsertManyOptions { IsOrdered = false }; private static readonly InsertManyOptions Unordered = new InsertManyOptions { IsOrdered = false };
private readonly RequestLogStoreOptions options;
public MongoRequestLogRepository(IMongoDatabase database) public MongoRequestLogRepository(IMongoDatabase database, IOptions<RequestLogStoreOptions> options)
: base(database) : base(database)
{ {
Guard.NotNull(options);
this.options = options.Value;
} }
protected override string CollectionName() protected override string CollectionName()
@ -44,7 +49,7 @@ namespace Squidex.Infrastructure.Log
.Ascending(x => x.Timestamp), .Ascending(x => x.Timestamp),
new CreateIndexOptions new CreateIndexOptions
{ {
ExpireAfter = TimeSpan.FromDays(90) ExpireAfter = TimeSpan.FromDays(options.StoreRetentionInDays)
}), }),
}, ct); }, ct);
} }

14
backend/src/Squidex.Infrastructure/Log/Store/RequestLogStoreOptions.cs

@ -0,0 +1,14 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.Log.Store
{
public sealed class RequestLogStoreOptions
{
public int StoreRetentionInDays { get; set; } = 90;
}
}

3
backend/src/Squidex/Config/Domain/LoggingServices.cs

@ -36,6 +36,9 @@ namespace Squidex.Config.Domain
services.Configure<RequestLogOptions>( services.Configure<RequestLogOptions>(
config.GetSection("logging")); config.GetSection("logging"));
services.Configure<RequestLogStoreOptions>(
config.GetSection("logging"));
services.Configure<SemanticLogOptions>( services.Configure<SemanticLogOptions>(
config.GetSection("logging")); config.GetSection("logging"));

6
backend/src/Squidex/appsettings.json

@ -251,7 +251,11 @@
/* /*
* Set to true to enable logging of profiler information. * Set to true to enable logging of profiler information.
*/ */
"logProfiler": false "logProfiler": false,
/*
* The number of days request log items will be stored.
*/
"storeRetentationInDays": 90
}, },
"assetStore": { "assetStore": {

Loading…
Cancel
Save