diff --git a/docs/GatewayConfiguration.md b/docs/GatewayConfiguration.md index 04d425d7..f1d78b26 100644 --- a/docs/GatewayConfiguration.md +++ b/docs/GatewayConfiguration.md @@ -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-.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) diff --git a/src/ZB.MOM.WW.MxGateway.Server/appsettings.Development.json b/src/ZB.MOM.WW.MxGateway.Server/appsettings.Development.json index 674b2e0f..6d75d9d7 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/appsettings.Development.json +++ b/src/ZB.MOM.WW.MxGateway.Server/appsettings.Development.json @@ -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 + } + } ] } } diff --git a/src/ZB.MOM.WW.MxGateway.Server/appsettings.json b/src/ZB.MOM.WW.MxGateway.Server/appsettings.json index 087fa068..5eabc8b4 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/appsettings.json +++ b/src/ZB.MOM.WW.MxGateway.Server/appsettings.json @@ -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": "*", diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Configuration/SerilogFileSinkRetentionTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Configuration/SerilogFileSinkRetentionTests.cs new file mode 100644 index 00000000..62f91685 --- /dev/null +++ b/src/ZB.MOM.WW.MxGateway.Tests/Configuration/SerilogFileSinkRetentionTests.cs @@ -0,0 +1,30 @@ +using Microsoft.Extensions.Configuration; + +namespace ZB.MOM.WW.MxGateway.Tests.Configuration; + +/// +/// Guards the shipped appsettings.json Serilog file sink against regressing to an unbounded +/// configuration (mxaccessgw#208). +/// +public sealed class SerilogFileSinkRetentionTests +{ + /// The shipped file sink caps both the retained file count and the per-file size. + [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); + } +}