Skip to content

Commit 8f56da6

Browse files
committed
Added Week to the RollingInterval enum.
Added a test for Week in RollingIntervalExtenstionsTests class.
1 parent 512587f commit 8f56da6

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/Serilog.Sinks.File/RollingInterval.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public enum RollingInterval
3434
/// </summary>
3535
Month,
3636

37+
/// <summary>
38+
/// Roll every calendar week. Filenames will have <code>yyyyMMdd</code> appended.
39+
/// </summary>
40+
Week,
41+
3742
/// <summary>
3843
/// Roll every day. Filenames will have <code>yyyyMMdd</code> appended.
3944
/// </summary>

src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static string GetFormat(this RollingInterval interval)
2828
return "yyyy";
2929
case RollingInterval.Month:
3030
return "yyyyMM";
31+
case RollingInterval.Week:
32+
return "yyyyMMdd";
3133
case RollingInterval.Day:
3234
return "yyyyMMdd";
3335
case RollingInterval.Hour:
@@ -49,6 +51,8 @@ public static string GetFormat(this RollingInterval interval)
4951
return new DateTime(instant.Year, 1, 1, 0, 0, 0, instant.Kind);
5052
case RollingInterval.Month:
5153
return new DateTime(instant.Year, instant.Month, 1, 0, 0, 0, instant.Kind);
54+
case RollingInterval.Week:
55+
return new DateTime(instant.Year, instant.Month, instant.Day, 0, 0, 0, instant.Kind);
5256
case RollingInterval.Day:
5357
return new DateTime(instant.Year, instant.Month, instant.Day, 0, 0, 0, instant.Kind);
5458
case RollingInterval.Hour:
@@ -72,6 +76,8 @@ public static string GetFormat(this RollingInterval interval)
7276
return current.Value.AddYears(1);
7377
case RollingInterval.Month:
7478
return current.Value.AddMonths(1);
79+
case RollingInterval.Week:
80+
return current.Value.AddDays(7);
7581
case RollingInterval.Day:
7682
return current.Value.AddDays(1);
7783
case RollingInterval.Hour:

test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class RollingIntervalExtensionsTests
1212
new object[]{ RollingInterval.Year, new DateTime(2018, 06, 01), new DateTime(2018, 01, 01), new DateTime(2019, 01, 01) },
1313
new object[]{ RollingInterval.Month, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 02, 01) },
1414
new object[]{ RollingInterval.Month, new DateTime(2018, 01, 14), new DateTime(2018, 01, 01), new DateTime(2018, 02, 01) },
15+
new object[]{ RollingInterval.Week, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 01, 08) },
16+
new object[]{ RollingInterval.Week, new DateTime(2018, 01, 01, 12, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 08) },
1517
new object[]{ RollingInterval.Day, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2018, 01, 02) },
1618
new object[]{ RollingInterval.Day, new DateTime(2018, 01, 01, 12, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 02) },
1719
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) },

test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
21+
<PackageReference Include="System.Runtime" Version="4.3.0" />
22+
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
2123
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
2224
<PackageReference Include="xunit" Version="2.4.1" />
2325
</ItemGroup>

0 commit comments

Comments
 (0)