Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serilog File Rolling Issue: Incorrect File Sizes with fileSizeLimitBytes #332

Open
WuJieFly opened this issue Jan 2, 2025 · 1 comment
Labels

Comments

@WuJieFly
Copy link

WuJieFly commented Jan 2, 2025

The Serilog maintainers want you to have a great experience using Serilog.Sinks.File, and will happily track down and resolve bugs. We all have limited time, though, so please think through all of the factors that might be involved and include as much useful information as possible 😊.

ℹ If the problem is caused by a sink or other extension package, please track down the correct repository for that package and create the report there: this tracker is for the Serilog.Sinks.File package only.

Description
When using Serilog's File sink with fileSizeLimitBytes configured, most log files adhere to the configured size limit (e.g., 20 MB), but occasionally, a single log file grows significantly larger than the limit (e.g., ~200 MB). This behavior occurs sporadically and disrupts expected log rotation.

Reproduction
cs:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.CreateBootstrapLogger();
...
builder.Host.UseSerilog((context,services,conf)=> conf
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext(),preserveStaticLogger:false,writeToProviders:true
);

appsetting.json:
"Serilog":{
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.AspNetCore":"Warning"
}
},
"WriteTo":[
{"Name": "Console"},
{
"Name": "File",
"Args": {
"path":"./log/log-.txt",
"rollingInterval":"Day",
"fileSizeLimitBytes":"20971520",
"rollOnFileSizeLimit":"true",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
},

Expected behavior
All log files should adhere to the fileSizeLimitBytes configuration (e.g., 20 MB) before rolling over to a new file.

Relevant package, tooling and runtime versions
What Serilog.Sinks.File version are you using, on what platform?
Serilog.AspNetCore: [6.1.0]

.NET Runtime Version: [NET 6.0.14]
Operating System: [Windows Server 2019]
Log Generation Frequency: High

Additional context

Most log files are correctly limited to the configured size (e.g., 20 MB).
Occasionally, a single file grows significantly larger than the limit (e.g., ~200 MB), disrupting the expected log rolling behavior.

Mode LastWriteTime Length Name


-a--- 2024/12/27 9:37 953177 log-20241227.txt
-a--- 2025/1/2 16:23 303583253 log-20250102.txt
-a--- 2025/1/2 16:24 21029204 log-20250102_001.txt
-a--- 2025/1/2 16:24 21466814 log-20250102_002.txt
-a--- 2025/1/2 16:24 24278806 log-20250102_003.txt
-a--- 2025/1/2 16:24 25562935 log-20250102_004.txt
-a--- 2025/1/2 16:25 207381106 log-20250102_005.txt
-a--- 2025/1/2 16:55 21056497 log-20250102_006.txt
-a--- 2025/1/2 16:55 21466815 log-20250102_007.txt
-a--- 2025/1/2 16:55 24278804 log-20250102_008.txt
-a--- 2025/1/2 16:55 25562934 log-20250102_009.txt
-a--- 2025/1/2 16:55 207381106 log-20250102_010.txt
-a--- 2025/1/2 16:55 738 log-20250102_011.txt

@WuJieFly WuJieFly added the bug label Jan 2, 2025
@nblumhardt
Copy link
Member

Hi! Does the larger log file contain one or more enormous single events? Files are rolled once they exceed the size limit, but sometimes the final event will push the size well past it. HTH!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants