-
Notifications
You must be signed in to change notification settings - Fork 122
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
Roll on year/month/day/hour/minute, on file size, or on a combination of both #35
Conversation
(Could use more test coverage; the tests are mostly for the scenarios that overlap with Serilog.Sinks.RollingFile - will loop back and try to add some more when possible.) |
Awesome work @nblumhardt! This will let me retire my forked sink with a messy implementation of these features. |
Looks great thanks. 👍 |
…ig from serilog/serilog
Great, thanks for taking a look! Any thoughts on naming, anything else? I guess the surface area is pretty low. My current thinking is that I'll try adding a few more tests, then merge this through to open up to wider feedback. |
Add: fix whatever is breaking the Travis build to that list :-) |
@@ -0,0 +1,31 @@ | |||
// Copyright 2013-2016 Serilog Contributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking : Year is now 2017 :) (also seen in several other files)
/// <param name="fileSizeLimitBytes">The approximate maximum size, in bytes, to which a log file will be allowed to grow. | ||
/// For unrestricted growth, pass null. The default is 1 GB. To avoid writing partial events, the last event within the limit | ||
/// will be written in full even if it exceeds the limit.</param> | ||
/// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default | ||
/// is false.</param> | ||
/// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param> | ||
/// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param> | ||
/// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param> | ||
/// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames | ||
/// will have a number appended in the format <code>_NNNNN</code>, with the first filename given no number.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the file is formatted with int.ToString("000"), I guess it should say "_NNN" here
@@ -92,6 +189,12 @@ public static class FileLoggerConfigurationExtensions | |||
/// is false.</param> | |||
/// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param> | |||
/// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param> | |||
/// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param> | |||
/// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames | |||
/// will have a number appended in the format <code>_NNNNN</code>, with the first filename given no number.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, shouldn't it be _NNN
?
} | ||
|
||
[Fact] | ||
public void AssemblyVersionIsFixedAt200() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that test pass, considering current File Sink (nuget package) version is at least v3.2.0+ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the feedback!
This one does pass - both sinks have had a frozen assembly version since 2.0.0, as a mitigation against the endless stream of binding redirect issues people hit (and report) otherwise :-)
[Fact] | ||
public void TheLogFileIncludesDateToken() | ||
{ | ||
var roller = new PathRoller("Logs\\log-.txt", RollingInterval.Day); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't backslashes problematic on Linux ? You should probably use Path.Combine
, or maybe Path.DirectorySeparatorChar
for the tests to work cross-platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe Path.GetInvalidFileNameChars
can be useful to avoid generating invalid filenames no matter the platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh well, I see it's covered :) 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the check; yes, just hacking away at this between other jobs today, missed your comment but have it covered now.
return new DateTime(instant.Year, 0, 0, 0, 0, 0, instant.Kind); | ||
case RollingInterval.Month: | ||
return new DateTime(instant.Year, instant.Month, 0, 0, 0, 0, instant.Kind); | ||
case RollingInterval.Day: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a lot of ArgumentOutOfRangeException
coming with the sample project, probably
new DateTime(instant.Year, 1, 1, 0, 0, 0, instant.Kind);
new DateTime(instant.Year, instant.Month, 1, 0, 0, 0, instant.Kind);
are needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixing now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Adding some tests....)
Finally made myself get WSL back up and running, instead of working in the dark, think everything should be running smoothly now. |
…kely this will be found in the short term
README updated: https://github.com/nblumhardt/serilog-sinks-file/blob/af88bceba9ef183e0e9520606541066c2fdf6d89/README.md Time to push this through to dev? What do you think, folks? :-) |
Didn't spot any issues more, looks great 👍 |
Thanks @skomis-mm |
Fixes serilog/serilog-sinks-rollingfile#33, Fixes serilog/serilog-sinks-rollingfile#52.
This PR introduces some additional parameters to
WriteTo.File()
.First,
rollOnFileSizeLimit
, causes additional log files to be created when the file size limit is reached. E.g.:will roll the file from
log.txt
tolog_001.txt
,log_002.txt
and so-on whenfileSizeLimitBytes
is reached (the default is 1 GB). Old files will be cleaned up as perretainedFileCountLimit
- the default is 31.A second parameter,
rollingInterval
, rolls the file byRollingInterval.Year
,Month
,Day
,Hour
orMinute
intolog20180101.txt
,log20180102.txt
and so on.If neither parameter is supplied, the behavior is exactly as before - the file name is static and no additional files will ever be created.
If both parameters are specified, the first file for a rolling interval will be named like
log20180101.txt
, rolling intolog20180101_001.txt
,log20180101.txt_002.txt
and so on, until the next interval when the counter resets.If either parameter is supplied, and the log file can't be opened, the suffix
_NNN
will be appended to find a filename that is available.Goals
-{Date}
path templates - they're misleading, as formatting information is not supported, and the placeholder can only appear in a very limited portion of the pathNon-goals
Breaking changes/evolution
*Sink
classes added in this PR are internal; the existing ones likeFileSink
are now marked[Obsolete]
so that they too can become internal in a far-future release, to support some refactoring and improvement of the architecture:u3
short level names and:lj
message formatting (this is the reason for the major version bump)I'm sure I'll think of more :-)