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

add rollOnFileSizeLimit #60

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

kgrodimov
Copy link

@kgrodimov kgrodimov commented Jul 6, 2023

@SimonCropp
Copy link

some tests might be hlpful

@kgrodimov
Copy link
Author

write unit tests or test locally and attach screenshot that code working?

@kgrodimov
Copy link
Author

for now, project do not have any tests) that's why I am asking) https://github.com/serilog/serilog-extensions-logging-file/tree/dev/test/Serilog.Extensions.Logging.File.Tests

Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this.

README.md Outdated
@@ -109,7 +109,13 @@ log-20160701.txt
log-20160702.txt
```

To prevent outages due to disk space exhaustion, each file is capped to 1 GB in size. If the file size is exceeded, events will be dropped until the next roll point.
To prevent outages due to disk space exhaustion, each file is capped to 1 GB in size. If the file size is exceeded, events will be dropped until the next roll point or new file with number appended in the format <code>_NNN</code>, with the first filename given no number, if rollOnFileSizeLimit is true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a non-default option, I think we can keep this simple and add the new information under the documentation for the rollOnFileSizeLimit parameter only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -3,6 +3,8 @@
"PathFormat": "Logs/log-{Date}.txt",
"OutputTemplate": "{Timestamp:o} {RequestId,13} [{Level:u3}] {Message} ({EventId:x8}) {Properties:j}{NewLine}{Exception}",
"IncludeScopes": true,
"RollOnFileSizeLimit": true,
"FileSizeLimitBytes": 10485760,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include these here; while they're useful, only a handful of users will want to configure them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah just tested locally and left for tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -117,9 +122,10 @@ public static ILoggingBuilder AddFile(this ILoggingBuilder loggingBuilder, IConf
bool isJson = false,
long? fileSizeLimitBytes = FileLoggingConfiguration.DefaultFileSizeLimitBytes,
int? retainedFileCountLimit = FileLoggingConfiguration.DefaultRetainedFileCountLimit,
string outputTemplate = FileLoggingConfiguration.DefaultOutputTemplate)
string outputTemplate = FileLoggingConfiguration.DefaultOutputTemplate,
bool rollOnFileSizeLimit = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a binary breaking change, we should bump the version number to 4.0.0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed number

<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to migrate to Serilog.Sinks.File without a substantial breaking change because of the differences in path formatting and rolling options; I think it's time we migrated, but there's more to discuss around it, so it'd be best discussed in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I do not need to migrate in this pr? I do not see any option in old library about it, https://github.com/serilog/serilog-sinks-rollingfile/blob/dev/src/Serilog.Sinks.RollingFile/RollingFileLoggerConfigurationExtensions.cs and without option rotation will not work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nblumhardt Hello, can you help here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kgrodimov - no need to migrate in this PR. The old library determines the rolling interval from the output path format string - if it includes {Date} then it rolls by day, etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how can I add roll by size if old library does not support this parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, for not answering. I think throw exception is a better way, as user can expect to roll by HalfHour, for example.

So I need to check, if path contains:
{Date}, {Hour},{HalfHour} - params from there, https://github.com/serilog/serilog-sinks-rollingfile#filename-format-specifiers and throw exception something like this: $"File name format {pathString} is not supported, use 'rollingInterval' parameter for rolling by time". And also add required rollingInterval param passing and add this param to docs.

Something else?
@nblumhardt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the log-{Date}.txt will cover the overwhelming majority of cases our there, so it'd be nice to keep accepting that and just trim out the {Date} to make the file paths compatible with the new implementation. We might end up with a flood of breakage/support otherwise.

This only works when {Date} immediately precedes the extension. If any other specifiers are there, or {Date} appears elsewhere in the path, we'd want to throw an exception.

If you're keen to explore it, we could also consider adding a RollingInterval argument and a shared flag, which would then cover 99% of the use cases for File.

HTH!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just trim out rollingInterval only if it immediately precedes the extension and pass correct interval with RollingInterval to Serilog.Sinks.File according to parsed value. So not only {Date}, but {Hour}, {HalfHour} also, or just {Day} as most popular.

New library does not support {HalfHour} btw, https://github.com/serilog/serilog-sinks-file/blob/2d2e00b31c4c1ed36dbbca8f4a43389856964fae/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs#L23. So for {HalfHour} can I throw exception?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the slow reply; yes, I think throwing an exception in that case would make sense 👍

@kgrodimov kgrodimov requested a review from nblumhardt July 19, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants