Skip to content

Support more options for rolling interval #204

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Serilog.Sinks.File/RollingInterval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public enum RollingInterval
/// </summary>
Month,

/// <summary>
/// Roll every calendar week. Filenames will have <code>yyyyMMdd</code> appended.
/// </summary>
Week,

/// <summary>
/// Roll every day. Filenames will have <code>yyyyMMdd</code> appended.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.File/Serilog.Sinks.File.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageTags>serilog;file</PackageTags>
<PackageIcon>images\icon.png</PackageIcon>
<PackageIconUrl>https://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
<PackageProjectUrl>http://serilog.net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageLicense>http://www.apache.org/licenses/LICENSE-2.0</PackageLicense>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-file</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static string GetFormat(this RollingInterval interval)
return "yyyy";
case RollingInterval.Month:
return "yyyyMM";
case RollingInterval.Week:
return "yyyyMMdd";
case RollingInterval.Day:
return "yyyyMMdd";
case RollingInterval.Hour:
Expand All @@ -49,6 +51,8 @@ public static string GetFormat(this RollingInterval interval)
return new DateTime(instant.Year, 1, 1, 0, 0, 0, instant.Kind);
case RollingInterval.Month:
return new DateTime(instant.Year, instant.Month, 1, 0, 0, 0, instant.Kind);
case RollingInterval.Week:
return new DateTime(instant.Year, instant.Month, instant.Day, 0, 0, 0, instant.Kind);
case RollingInterval.Day:
return new DateTime(instant.Year, instant.Month, instant.Day, 0, 0, 0, instant.Kind);
case RollingInterval.Hour:
Expand All @@ -72,6 +76,8 @@ public static string GetFormat(this RollingInterval interval)
return current.Value.AddYears(1);
case RollingInterval.Month:
return current.Value.AddMonths(1);
case RollingInterval.Week:
return current.Value.AddDays(7);
case RollingInterval.Day:
return current.Value.AddDays(1);
case RollingInterval.Hour:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class RollingIntervalExtensionsTests
new object[]{ RollingInterval.Year, new DateTime(2018, 06, 01), new DateTime(2018, 01, 01), new DateTime(2019, 01, 01) },
new object[]{ RollingInterval.Month, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 02, 01) },
new object[]{ RollingInterval.Month, new DateTime(2018, 01, 14), new DateTime(2018, 01, 01), new DateTime(2018, 02, 01) },
new object[]{ RollingInterval.Week, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 01, 08) },
new object[]{ RollingInterval.Week, new DateTime(2018, 01, 01, 12, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 08) },
new object[]{ RollingInterval.Day, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 01, 02) },
new object[]{ RollingInterval.Day, new DateTime(2018, 01, 01, 12, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 02) },
new object[]{ RollingInterval.Hour, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 1, 0, 0) },
Expand Down
2 changes: 2 additions & 0 deletions test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
Expand Down