fix(server): cap Serilog file-sink retention and size (mxaccessgw#208)
Set retainedFileCountLimit=30, fileSizeLimitBytes=50 MiB and rollOnFileSizeLimit=true on the file sink in appsettings.json and appsettings.Development.json; document under a new Logging section in docs/GatewayConfiguration.md; add a guard test over the shipped config.
This commit is contained in:
@@ -7,7 +7,16 @@
|
||||
},
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" },
|
||||
{ "Name": "File", "Args": { "path": "logs/mxgateway-.log", "rollingInterval": "Day" } }
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/mxgateway-.log",
|
||||
"rollingInterval": "Day",
|
||||
"retainedFileCountLimit": 30,
|
||||
"fileSizeLimitBytes": 52428800,
|
||||
"rollOnFileSizeLimit": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,16 @@
|
||||
},
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" },
|
||||
{ "Name": "File", "Args": { "path": "logs/mxgateway-.log", "rollingInterval": "Day" } }
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/mxgateway-.log",
|
||||
"rollingInterval": "Day",
|
||||
"retainedFileCountLimit": 30,
|
||||
"fileSizeLimitBytes": 52428800,
|
||||
"rollOnFileSizeLimit": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Guards the shipped <c>appsettings.json</c> Serilog file sink against regressing to an unbounded
|
||||
/// configuration (mxaccessgw#208).
|
||||
/// </summary>
|
||||
public sealed class SerilogFileSinkRetentionTests
|
||||
{
|
||||
/// <summary>The shipped file sink caps both the retained file count and the per-file size.</summary>
|
||||
[Theory]
|
||||
[InlineData("appsettings.json")]
|
||||
[InlineData("appsettings.Development.json")]
|
||||
public void ShippedFileSink_HasRetentionAndSizeCaps(string fileName)
|
||||
{
|
||||
IConfigurationRoot config = new ConfigurationBuilder()
|
||||
.AddJsonFile(Path.Combine(AppContext.BaseDirectory, "appsettings.json"), optional: false)
|
||||
.AddJsonFile(Path.Combine(AppContext.BaseDirectory, fileName), optional: false)
|
||||
.Build();
|
||||
|
||||
IConfigurationSection fileSink = config.GetSection("Serilog:WriteTo").GetChildren()
|
||||
.Single(section => section["Name"] == "File")
|
||||
.GetSection("Args");
|
||||
|
||||
Assert.True(int.TryParse(fileSink["retainedFileCountLimit"], out int retained) && retained is > 0 and <= 365);
|
||||
Assert.True(long.TryParse(fileSink["fileSizeLimitBytes"], out long sizeLimit) && sizeLimit > 0);
|
||||
Assert.Equal("true", fileSink["rollOnFileSizeLimit"], ignoreCase: true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user