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:
@@ -742,6 +742,22 @@ protected DACL whose only entry grants its own account (the account the worker
|
||||
is launched as); on the non-Windows test matrix it uses
|
||||
`PipeOptions.CurrentUserOnly`. See `WorkerPipeSecurity` and [Worker Frame Protocol](./WorkerFrameProtocol.md).
|
||||
|
||||
## Logging (Serilog file sink)
|
||||
|
||||
Logging is configured under the top-level `Serilog` section (not `MxGateway`) in `appsettings.json`. The file
|
||||
sink writes `logs/mxgateway-<date>.log` and is bounded so a long-running gateway cannot fill its disk:
|
||||
|
||||
| Key (`Serilog:WriteTo:1:Args:`) | Shipped value | Meaning |
|
||||
|---|---|---|
|
||||
| `rollingInterval` | `Day` | A new file per day. |
|
||||
| `retainedFileCountLimit` | `30` | Keep at most 30 files; older ones are deleted when a new file is created. |
|
||||
| `fileSizeLimitBytes` | `52428800` (50 MiB) | Per-file size cap. |
|
||||
| `rollOnFileSizeLimit` | `true` | Start a new file at the cap instead of silently dropping events for the rest of the day (the Serilog default when a size limit is set without this flag). |
|
||||
|
||||
Worst-case on-disk log footprint is therefore about `retainedFileCountLimit x fileSizeLimitBytes` (1.5 GiB).
|
||||
Raise or lower these in the deployed `appsettings.json` (or via `Serilog__WriteTo__1__Args__*` environment
|
||||
variables) to fit the host's disk budget.
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [Gateway Process Detailed Design](./GatewayProcessDesign.md)
|
||||
|
||||
@@ -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