From 8f56da60d7b029d75ec203398fb6964203274a99 Mon Sep 17 00:00:00 2001 From: Cameron Belt Date: Mon, 12 Oct 2020 16:53:18 -0500 Subject: [PATCH 1/4] Added Week to the RollingInterval enum. Added a test for Week in RollingIntervalExtenstionsTests class. --- src/Serilog.Sinks.File/RollingInterval.cs | 5 +++++ .../Sinks/File/RollingIntervalExtensions.cs | 6 ++++++ .../RollingIntervalExtensionsTests.cs | 2 ++ .../Serilog.Sinks.File.Tests.csproj | 2 ++ 4 files changed, 15 insertions(+) diff --git a/src/Serilog.Sinks.File/RollingInterval.cs b/src/Serilog.Sinks.File/RollingInterval.cs index 9fac848..7b013d9 100644 --- a/src/Serilog.Sinks.File/RollingInterval.cs +++ b/src/Serilog.Sinks.File/RollingInterval.cs @@ -34,6 +34,11 @@ public enum RollingInterval /// Month, + /// + /// Roll every calendar week. Filenames will have yyyyMMdd appended. + /// + Week, + /// /// Roll every day. Filenames will have yyyyMMdd appended. /// diff --git a/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs b/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs index 2c9e2fd..101a0ef 100644 --- a/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs +++ b/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs @@ -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: @@ -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: @@ -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: diff --git a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs index 2d97d1b..8cc0914 100644 --- a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs @@ -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) }, diff --git a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj index fcf2880..8c99f35 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -18,6 +18,8 @@ + + From 752449b293764c7e0b34dc39b1eaa5d12aabc4fa Mon Sep 17 00:00:00 2001 From: Cameron Belt Date: Mon, 12 Oct 2020 17:05:30 -0500 Subject: [PATCH 2/4] Update property group tags. --- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index f498bf6..17cafbf 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -10,9 +10,9 @@ true true serilog;file - http://serilog.net/images/serilog-sink-nuget.png + http://serilog.net/images/serilog-sink-nuget.png http://serilog.net - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 https://github.com/serilog/serilog-sinks-file git false From de4bb4b759dd4843c7524346895d3c9e94d73320 Mon Sep 17 00:00:00 2001 From: Cameron Belt Date: Mon, 12 Oct 2020 17:11:22 -0500 Subject: [PATCH 3/4] Changed from PackageIcon to IconUrl --- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index 17cafbf..d4ada86 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -10,7 +10,7 @@ true true serilog;file - http://serilog.net/images/serilog-sink-nuget.png + http://serilog.net/images/serilog-sink-nuget.png http://serilog.net http://www.apache.org/licenses/LICENSE-2.0 https://github.com/serilog/serilog-sinks-file From cc815136530a2c0a3b6afc40cb70dadfe72ee186 Mon Sep 17 00:00:00 2001 From: "Rafael Nicoletti@ubuntu" Date: Fri, 19 Feb 2021 15:24:40 +0000 Subject: [PATCH 4/4] allow more granular rolling intervals: - FiveMinutes - TenMinutes - QuarterHour - HalfHour --- src/Serilog.Sinks.File/RollingInterval.cs | 22 ++++++++++++++++++- .../Sinks/File/RollingIntervalExtensions.cs | 22 ++++++++++++++++++- .../RollingIntervalExtensionsTests.cs | 18 +++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.File/RollingInterval.cs b/src/Serilog.Sinks.File/RollingInterval.cs index 7b013d9..d12bf18 100644 --- a/src/Serilog.Sinks.File/RollingInterval.cs +++ b/src/Serilog.Sinks.File/RollingInterval.cs @@ -52,6 +52,26 @@ public enum RollingInterval /// /// Roll every minute. Filenames will have yyyyMMddHHmm appended. /// - Minute + Minute, + + /// + /// Roll every five minute. Filenames will have yyyyMMddHHmm appended with minutes limited to multiples of five. + /// + FiveMinutes, + + /// + /// Roll every ten minute. Filenames will have yyyyMMddHHmm appended with minutes limited to multiples of ten. + /// + TenMinutes, + + /// + /// Roll every fifteen minute. Filenames will have yyyyMMddHHmm appended with minutes limited to multiples of fifteen. + /// + QuarterHour, + + /// + /// Roll every half hour. Filenames will have yyyyMMddHHmm appended with minutes limited to multiples of third. + /// + HalfHour } } diff --git a/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs b/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs index 101a0ef..949cfba 100644 --- a/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs +++ b/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs @@ -1,4 +1,4 @@ -// Copyright 2017 Serilog Contributors +// Copyright 2017 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,6 +35,10 @@ public static string GetFormat(this RollingInterval interval) case RollingInterval.Hour: return "yyyyMMddHH"; case RollingInterval.Minute: + case RollingInterval.FiveMinutes: + case RollingInterval.TenMinutes: + case RollingInterval.QuarterHour: + case RollingInterval.HalfHour: return "yyyyMMddHHmm"; default: throw new ArgumentException("Invalid rolling interval"); @@ -59,6 +63,14 @@ public static string GetFormat(this RollingInterval interval) return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, 0, 0, instant.Kind); case RollingInterval.Minute: return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, instant.Minute, 0, instant.Kind); + case RollingInterval.FiveMinutes: + return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, (int)(instant.Minute / 5) * 5, 0, instant.Kind); + case RollingInterval.TenMinutes: + return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, (int)(instant.Minute / 10) * 10, 0, instant.Kind); + case RollingInterval.QuarterHour: + return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, (int)(instant.Minute / 15) * 15, 0, instant.Kind); + case RollingInterval.HalfHour: + return new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, (int)(instant.Minute / 30) * 30, 0, instant.Kind); default: throw new ArgumentException("Invalid rolling interval"); } @@ -84,6 +96,14 @@ public static string GetFormat(this RollingInterval interval) return current.Value.AddHours(1); case RollingInterval.Minute: return current.Value.AddMinutes(1); + case RollingInterval.FiveMinutes: + return current.Value.AddMinutes(5); + case RollingInterval.TenMinutes: + return current.Value.AddMinutes(10); + case RollingInterval.QuarterHour: + return current.Value.AddMinutes(15); + case RollingInterval.HalfHour: + return current.Value.AddMinutes(30); default: throw new ArgumentException("Invalid rolling interval"); } diff --git a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs index 8cc0914..bad8af7 100644 --- a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs @@ -18,6 +18,24 @@ public class RollingIntervalExtensionsTests 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) }, new object[]{ RollingInterval.Hour, new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 1, 0, 0) }, + new object[]{ RollingInterval.HalfHour, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 0, 30, 0) }, + new object[]{ RollingInterval.HalfHour, new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 1, 00, 0) }, + new object[]{ RollingInterval.HalfHour, new DateTime(2018, 01, 01, 0, 45, 0), new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 1, 0, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 0, 15, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 10, 0), new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01, 0, 15, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 15, 0), new DateTime(2018, 01, 01, 0, 15, 0), new DateTime(2018, 01, 01, 0, 30, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 20, 0), new DateTime(2018, 01, 01, 0, 15, 0), new DateTime(2018, 01, 01, 0, 30, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 0, 45, 0) }, + new object[]{ RollingInterval.QuarterHour, new DateTime(2018, 01, 01, 0, 45, 0), new DateTime(2018, 01, 01, 0, 45, 0), new DateTime(2018, 01, 01, 1, 0, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 0, 10, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 10, 0), new DateTime(2018, 01, 01, 0, 10, 0), new DateTime(2018, 01, 01, 0, 20, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 15, 0), new DateTime(2018, 01, 01, 0, 10, 0), new DateTime(2018, 01, 01, 0, 20, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 20, 0), new DateTime(2018, 01, 01, 0, 20, 0), new DateTime(2018, 01, 01, 0, 30, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 0, 30, 0), new DateTime(2018, 01, 01, 0, 40, 0) }, + new object[]{ RollingInterval.TenMinutes, new DateTime(2018, 01, 01, 0, 45, 0), new DateTime(2018, 01, 01, 0, 40, 0), new DateTime(2018, 01, 01, 0, 50, 0) }, + new object[]{ RollingInterval.FiveMinutes, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01, 0, 5, 0) }, + new object[]{ RollingInterval.FiveMinutes, new DateTime(2018, 01, 01, 0, 4, 0), new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01, 0, 5, 0) }, + new object[]{ RollingInterval.FiveMinutes, new DateTime(2018, 01, 01, 0, 6, 0), new DateTime(2018, 01, 01, 0, 5, 0), new DateTime(2018, 01, 01, 0, 10, 0) }, new object[]{ RollingInterval.Minute, new DateTime(2018, 01, 01, 0, 0, 0), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 0, 1, 0) }, new object[]{ RollingInterval.Minute, new DateTime(2018, 01, 01, 0, 0, 30), new DateTime(2018, 01, 01), new DateTime(2018, 01, 01, 0, 1, 0) } };