From 6d00e50a3a46adf5ee6878986a4a2d73f8719d3b Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Sun, 19 Jul 2020 22:58:48 -0700 Subject: [PATCH 01/13] Initial Nullable Support --- .../FileLoggerConfigurationExtensions.cs | 36 ++--- .../Serilog.Sinks.File.csproj | 12 +- src/Serilog.Sinks.File/Sinks/File/FileSink.cs | 6 +- .../Sinks/File/RollingFileSink.cs | 10 +- .../Sinks/File/SharedFileSink.OSMutex.cs | 2 +- .../Support/NullableAttributes..cs | 140 ++++++++++++++++++ .../RollingFileSinkTests.cs | 4 +- .../Serilog.Sinks.File.Tests.csproj | 7 +- .../Support/DelegatingSink.cs | 4 +- .../Support/Extensions.cs | 2 +- .../Support/TempFolder.cs | 6 +- 11 files changed, 190 insertions(+), 39 deletions(-) create mode 100644 src/Serilog.Sinks.File/Support/NullableAttributes..cs diff --git a/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs index 74383b2..782eaaa 100644 --- a/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs @@ -243,17 +243,17 @@ public static LoggerConfiguration File( string path, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, string outputTemplate = DefaultOutputTemplate, - IFormatProvider formatProvider = null, + IFormatProvider? formatProvider = null, long? fileSizeLimitBytes = DefaultFileSizeLimitBytes, - LoggingLevelSwitch levelSwitch = null, + LoggingLevelSwitch? levelSwitch = null, bool buffered = false, bool shared = false, TimeSpan? flushToDiskInterval = null, RollingInterval rollingInterval = RollingInterval.Infinite, bool rollOnFileSizeLimit = false, int? retainedFileCountLimit = DefaultRetainedFileCountLimit, - Encoding encoding = null, - FileLifecycleHooks hooks = null, + Encoding? encoding = null, + FileLifecycleHooks? hooks = null, TimeSpan? retainedFileTimeLimit = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); @@ -305,15 +305,15 @@ public static LoggerConfiguration File( string path, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, long? fileSizeLimitBytes = DefaultFileSizeLimitBytes, - LoggingLevelSwitch levelSwitch = null, + LoggingLevelSwitch? levelSwitch = null, bool buffered = false, bool shared = false, TimeSpan? flushToDiskInterval = null, RollingInterval rollingInterval = RollingInterval.Infinite, bool rollOnFileSizeLimit = false, int? retainedFileCountLimit = DefaultRetainedFileCountLimit, - Encoding encoding = null, - FileLifecycleHooks hooks = null, + Encoding? encoding = null, + FileLifecycleHooks? hooks = null, TimeSpan? retainedFileTimeLimit = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); @@ -398,10 +398,10 @@ public static LoggerConfiguration File( string path, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, string outputTemplate = DefaultOutputTemplate, - IFormatProvider formatProvider = null, - LoggingLevelSwitch levelSwitch = null, - Encoding encoding = null, - FileLifecycleHooks hooks = null) + IFormatProvider? formatProvider = null, + LoggingLevelSwitch? levelSwitch = null, + Encoding? encoding = null, + FileLifecycleHooks? hooks = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (path == null) throw new ArgumentNullException(nameof(path)); @@ -433,9 +433,9 @@ public static LoggerConfiguration File( ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - LoggingLevelSwitch levelSwitch = null, - Encoding encoding = null, - FileLifecycleHooks hooks = null) + LoggingLevelSwitch? levelSwitch = null, + Encoding? encoding = null, + FileLifecycleHooks? hooks = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (formatter == null) throw new ArgumentNullException(nameof(formatter)); @@ -446,21 +446,21 @@ public static LoggerConfiguration File( } static LoggerConfiguration ConfigureFile( - this Func addSink, + this Func addSink, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel, long? fileSizeLimitBytes, - LoggingLevelSwitch levelSwitch, + LoggingLevelSwitch? levelSwitch, bool buffered, bool propagateExceptions, bool shared, TimeSpan? flushToDiskInterval, - Encoding encoding, + Encoding? encoding, RollingInterval rollingInterval, bool rollOnFileSizeLimit, int? retainedFileCountLimit, - FileLifecycleHooks hooks, + FileLifecycleHooks? hooks, TimeSpan? retainedFileTimeLimit) { if (addSink == null) throw new ArgumentNullException(nameof(addSink)); diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index f498bf6..1d65ab7 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -4,7 +4,7 @@ Write Serilog events to text files in plain or JSON format. 5.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp3.0 + net45;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.0;netcoreapp3.1 true ../../assets/Serilog.snk true @@ -24,6 +24,11 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + 8.0 + enable + + @@ -37,7 +42,7 @@ $(DefineConstants);OS_MUTEX - + $(DefineConstants);OS_MUTEX @@ -51,9 +56,10 @@ - + + diff --git a/src/Serilog.Sinks.File/Sinks/File/FileSink.cs b/src/Serilog.Sinks.File/Sinks/File/FileSink.cs index 451ba55..0ed30d4 100644 --- a/src/Serilog.Sinks.File/Sinks/File/FileSink.cs +++ b/src/Serilog.Sinks.File/Sinks/File/FileSink.cs @@ -31,7 +31,7 @@ public sealed class FileSink : IFileSink, IDisposable readonly long? _fileSizeLimitBytes; readonly bool _buffered; readonly object _syncRoot = new object(); - readonly WriteCountingStream _countingStreamWrapper; + readonly WriteCountingStream? _countingStreamWrapper; /// Construct a . /// Path to the file. @@ -56,9 +56,9 @@ internal FileSink( string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, - Encoding encoding, + Encoding? encoding, bool buffered, - FileLifecycleHooks hooks) + FileLifecycleHooks? hooks) { if (path == null) throw new ArgumentNullException(nameof(path)); if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 1) throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null."); diff --git a/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs b/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs index 0eb4463..25b886a 100644 --- a/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs +++ b/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs @@ -30,28 +30,28 @@ sealed class RollingFileSink : ILogEventSink, IFlushableFileSink, IDisposable readonly long? _fileSizeLimitBytes; readonly int? _retainedFileCountLimit; readonly TimeSpan? _retainedFileTimeLimit; - readonly Encoding _encoding; + readonly Encoding? _encoding; readonly bool _buffered; readonly bool _shared; readonly bool _rollOnFileSizeLimit; - readonly FileLifecycleHooks _hooks; + readonly FileLifecycleHooks? _hooks; readonly object _syncRoot = new object(); bool _isDisposed; DateTime? _nextCheckpoint; - IFileSink _currentFile; + IFileSink? _currentFile; int? _currentFileSequence; public RollingFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, int? retainedFileCountLimit, - Encoding encoding, + Encoding? encoding, bool buffered, bool shared, RollingInterval rollingInterval, bool rollOnFileSizeLimit, - FileLifecycleHooks hooks, + FileLifecycleHooks? hooks, TimeSpan? retainedFileTimeLimit) { if (path == null) throw new ArgumentNullException(nameof(path)); diff --git a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs index 38b2326..8c380de 100644 --- a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs +++ b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs @@ -50,7 +50,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable /// Configuration object allowing method chaining. /// The file will be written using the UTF-8 character set. /// - public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding encoding = null) + public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding = null) { if (path == null) throw new ArgumentNullException(nameof(path)); if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 1) diff --git a/src/Serilog.Sinks.File/Support/NullableAttributes..cs b/src/Serilog.Sinks.File/Support/NullableAttributes..cs new file mode 100644 index 0000000..c7a2018 --- /dev/null +++ b/src/Serilog.Sinks.File/Support/NullableAttributes..cs @@ -0,0 +1,140 @@ +#pragma warning disable MA0048 // File name must match type name +#define INTERNAL_NULLABLE_ATTRIBUTES +#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETSTANDARD2_0 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 + +// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Diagnostics.CodeAnalysis +{ + /// Specifies that null is allowed as an input even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class AllowNullAttribute : Attribute + { } + + /// Specifies that null is disallowed as an input even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DisallowNullAttribute : Attribute + { } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullAttribute : Attribute + { } + + /// Specifies that an output will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullAttribute : Attribute + { } + + /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter may be null. + /// + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; + + /// Gets the associated parameter name. + public string ParameterName { get; } + } + + /// Applied to a method that will never return under any circumstance. + [AttributeUsage(AttributeTargets.Method, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnAttribute : Attribute + { } + + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnIfAttribute : Attribute + { + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } + } +} +#endif diff --git a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs index d295dfc..9e8a9b9 100644 --- a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs @@ -242,7 +242,7 @@ public void IfTheLogFolderDoesNotExistItWillBeCreated() var folder = Path.Combine(temp, Guid.NewGuid().ToString()); var pathFormat = Path.Combine(folder, fileName); - Logger log = null; + Logger? log = null; try { @@ -278,7 +278,7 @@ static void TestRollingEventSequence(params LogEvent[] events) static void TestRollingEventSequence( Action configureFile, IEnumerable events, - Action> verifyWritten = null) + Action>? verifyWritten = null) { var fileName = Some.String() + "-.txt"; var folder = Some.TempFolderPath(); 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..79d889a 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -1,7 +1,7 @@ - net47;netcoreapp3.1 + net452;net462;net472;net48;netcoreapp1.1;netcoreapp2.2;netcoreapp3.1 true Serilog.Sinks.File.Tests ../../assets/Serilog.snk @@ -12,6 +12,11 @@ 1.0.4 + + 8.0 + enable + + diff --git a/test/Serilog.Sinks.File.Tests/Support/DelegatingSink.cs b/test/Serilog.Sinks.File.Tests/Support/DelegatingSink.cs index 9d81cc2..12b7f3d 100644 --- a/test/Serilog.Sinks.File.Tests/Support/DelegatingSink.cs +++ b/test/Serilog.Sinks.File.Tests/Support/DelegatingSink.cs @@ -21,13 +21,13 @@ public void Emit(LogEvent logEvent) public static LogEvent GetLogEvent(Action writeAction) { - LogEvent result = null; + LogEvent? result = null; var l = new LoggerConfiguration() .WriteTo.Sink(new DelegatingSink(le => result = le)) .CreateLogger(); writeAction(l); - return result; + return result!; } } } diff --git a/test/Serilog.Sinks.File.Tests/Support/Extensions.cs b/test/Serilog.Sinks.File.Tests/Support/Extensions.cs index f7fb775..a048353 100644 --- a/test/Serilog.Sinks.File.Tests/Support/Extensions.cs +++ b/test/Serilog.Sinks.File.Tests/Support/Extensions.cs @@ -17,7 +17,7 @@ public static List ReadAllLines(this Stream @this) using (var reader = new StreamReader(@this)) { - string line; + string? line; while ((line = reader.ReadLine()) != null) { lines.Add(line); diff --git a/test/Serilog.Sinks.File.Tests/Support/TempFolder.cs b/test/Serilog.Sinks.File.Tests/Support/TempFolder.cs index 7ff90f8..29682e0 100644 --- a/test/Serilog.Sinks.File.Tests/Support/TempFolder.cs +++ b/test/Serilog.Sinks.File.Tests/Support/TempFolder.cs @@ -11,7 +11,7 @@ class TempFolder : IDisposable readonly string _tempFolder; - public TempFolder(string name = null) + public TempFolder(string? name = null) { _tempFolder = System.IO.Path.Combine( Environment.GetEnvironmentVariable("TMP") ?? Environment.GetEnvironmentVariable("TMPDIR") ?? "/tmp", @@ -37,7 +37,7 @@ public void Dispose() } } - public static TempFolder ForCaller([CallerMemberName] string caller = null, [CallerFilePath] string sourceFileName = "") + public static TempFolder ForCaller([CallerMemberName] string? caller = null, [CallerFilePath] string sourceFileName = "") { if (caller == null) throw new ArgumentNullException(nameof(caller)); if (sourceFileName == null) throw new ArgumentNullException(nameof(sourceFileName)); @@ -47,7 +47,7 @@ public static TempFolder ForCaller([CallerMemberName] string caller = null, [Cal return new TempFolder(folderName); } - public string AllocateFilename(string ext = null) + public string AllocateFilename(string? ext = null) { return System.IO.Path.Combine(Path, Guid.NewGuid().ToString("n") + "." + (ext ?? "tmp")); } From ecff836d9976ea1e0408fbd2b3b0a0f9a5babc7b Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Tue, 21 Jul 2020 22:56:00 -0700 Subject: [PATCH 02/13] Update Nullable Reference Support --- src/Serilog.Sinks.File/Sinks/File/FileSink.cs | 4 ++-- .../Sinks/File/RollingFileSink.cs | 4 ++-- .../Sinks/File/SharedFileSink.AtomicAppend.cs | 2 +- .../RollingFileSinkTests.cs | 2 +- .../RollingIntervalExtensionsTests.cs | 24 +++++++++---------- test/Serilog.Sinks.File.Tests/Support/Some.cs | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Serilog.Sinks.File/Sinks/File/FileSink.cs b/src/Serilog.Sinks.File/Sinks/File/FileSink.cs index 0ed30d4..d9a628c 100644 --- a/src/Serilog.Sinks.File/Sinks/File/FileSink.cs +++ b/src/Serilog.Sinks.File/Sinks/File/FileSink.cs @@ -46,7 +46,7 @@ public sealed class FileSink : IFileSink, IDisposable /// This constructor preserves compatibility with early versions of the public API. New code should not depend on this type. /// [Obsolete("This type and constructor will be removed from the public API in a future version; use `WriteTo.File()` instead.")] - public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding encoding = null, bool buffered = false) + public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding = null, bool buffered = false) : this(path, textFormatter, fileSizeLimitBytes, encoding, buffered, null) { } @@ -97,7 +97,7 @@ bool IFileSink.EmitOrOverflow(LogEvent logEvent) { if (_fileSizeLimitBytes != null) { - if (_countingStreamWrapper.CountedLength >= _fileSizeLimitBytes.Value) + if (_countingStreamWrapper!.CountedLength >= _fileSizeLimitBytes.Value) return false; } diff --git a/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs b/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs index 25b886a..dccb802 100644 --- a/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs +++ b/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs @@ -125,7 +125,7 @@ void OpenFile(DateTime now, int? minSequence = null) if (Directory.Exists(_roller.LogFileDirectory)) { existingFiles = Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern) - .Select(Path.GetFileName); + .Select(f => Path.GetFileName(f)); } } catch (DirectoryNotFoundException) { } @@ -184,7 +184,7 @@ void ApplyRetentionPolicy(string currentFilePath, DateTime now) // We consider the current file to exist, even if nothing's been written yet, // because files are only opened on response to an event being processed. var potentialMatches = Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern) - .Select(Path.GetFileName) + .Select(f => Path.GetFileName(f)) .Union(new[] { currentFileName }); var newestFirst = _roller diff --git a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs index 25e8867..9d67974 100644 --- a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs +++ b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs @@ -51,7 +51,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable /// Character encoding used to write the text file. The default is UTF-8 without BOM. /// Configuration object allowing method chaining. /// - public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding encoding = null) + public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding = null) { if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 1) throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null"); diff --git a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs index 9e8a9b9..bfe1fa3 100644 --- a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs @@ -265,7 +265,7 @@ public void IfTheLogFolderDoesNotExistItWillBeCreated() public void AssemblyVersionIsFixedAt200() { var assembly = typeof(FileLoggerConfigurationExtensions).GetTypeInfo().Assembly; - Assert.Equal("2.0.0.0", assembly.GetName().Version.ToString(4)); + Assert.Equal("2.0.0.0", assembly.GetName()?.Version?.ToString(4)); } static void TestRollingEventSequence(params LogEvent[] events) diff --git a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs index 2d97d1b..404d5b4 100644 --- a/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingIntervalExtensionsTests.cs @@ -5,19 +5,19 @@ namespace Serilog.Sinks.File.Tests { public class RollingIntervalExtensionsTests { - public static object[][] IntervalInstantCurrentNextCheckpoint => new[] + public static object?[][] IntervalInstantCurrentNextCheckpoint => new[] { - new object[]{ RollingInterval.Infinite, new DateTime(2018, 01, 01), null, null }, - new object[]{ RollingInterval.Year, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2019, 01, 01) }, - 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.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) }, - 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.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) } + new object?[]{ RollingInterval.Infinite, new DateTime(2018, 01, 01), null, null }, + new object?[]{ RollingInterval.Year, new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new DateTime(2019, 01, 01) }, + 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.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) }, + 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.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) } }; [Theory] diff --git a/test/Serilog.Sinks.File.Tests/Support/Some.cs b/test/Serilog.Sinks.File.Tests/Support/Some.cs index f0c7fd9..4209102 100644 --- a/test/Serilog.Sinks.File.Tests/Support/Some.cs +++ b/test/Serilog.Sinks.File.Tests/Support/Some.cs @@ -24,7 +24,7 @@ public static decimal Decimal() return Int() + 0.123m; } - public static string String(string tag = null) + public static string String(string? tag = null) { return (tag ?? "") + "__" + Int(); } From f2af026dd3c9a63ce5bc02af50322c15257bce81 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Tue, 21 Jul 2020 23:37:47 -0700 Subject: [PATCH 03/13] Update appveyor config --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7e41204..37b0420 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,14 +2,14 @@ version: '{build}' skip_tags: true image: - Visual Studio 2019 - - Ubuntu1804 + - Ubuntu build_script: - ps: ./Build.ps1 for: - matrix: only: - - image: Ubuntu1804 + - image: Ubuntu build_script: - sh build.sh test: off From 4db0db2a7db30a8e0fa17049b79b1e089ce75cb1 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 00:55:41 -0700 Subject: [PATCH 04/13] Update Test Project --- .../Serilog.Sinks.File.Tests.csproj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 79d889a..954f883 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -1,7 +1,7 @@ - + - net452;net462;net472;net48;netcoreapp1.1;netcoreapp2.2;netcoreapp3.1 + net452;net462;net472;net48;netcoreapp2.2;netcoreapp3.1 true Serilog.Sinks.File.Tests ../../assets/Serilog.snk @@ -22,8 +22,11 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 14855cfdc997038140a5ab6957d052dbd8f3f72d Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 01:03:46 -0700 Subject: [PATCH 05/13] Update Test Project --- test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 954f883..6cd191c 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -1,7 +1,7 @@  - net452;net462;net472;net48;netcoreapp2.2;netcoreapp3.1 + net48;netcoreapp3.1 true Serilog.Sinks.File.Tests ../../assets/Serilog.snk From 75774f0fabae54690f72ce572daccbf3c40449ab Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 23 Jul 2020 15:50:15 -0700 Subject: [PATCH 06/13] Code Format --- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index 1d65ab7..b619968 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -5,6 +5,8 @@ 5.0.0 Serilog Contributors net45;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.0;netcoreapp3.1 + 8.0 + enable true ../../assets/Serilog.snk true @@ -24,11 +26,6 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - 8.0 - enable - - From 9d3aa37e219dae66a2dba8210988fe4ea9e3c12d Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 23 Jul 2020 16:04:47 -0700 Subject: [PATCH 07/13] Code Refactor --- example/Sample/Sample.csproj | 2 ++ .../Serilog.Sinks.File.Tests.csproj | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/example/Sample/Sample.csproj b/example/Sample/Sample.csproj index e307db1..9574c3e 100644 --- a/example/Sample/Sample.csproj +++ b/example/Sample/Sample.csproj @@ -2,6 +2,8 @@ netcoreapp2.0;net47 + 8.0 + enable Sample Exe Sample 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 6cd191c..53429b9 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -2,6 +2,8 @@ net48;netcoreapp3.1 + 8.0 + enable true Serilog.Sinks.File.Tests ../../assets/Serilog.snk @@ -12,11 +14,6 @@ 1.0.4 - - 8.0 - enable - - From d171cbad3c48f5ae2b4a29393ee77a81950508b3 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 30 Jul 2020 00:09:00 -0700 Subject: [PATCH 08/13] Remove unnecessary references --- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index f498bf6..e40ed48 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -41,19 +41,4 @@ $(DefineConstants);OS_MUTEX - - - - - - - - - - - - - - - From 89d3b6510034f93ac9959d0cf978d20621295a81 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 30 Jul 2020 22:49:30 -0700 Subject: [PATCH 09/13] Simplifying Constants --- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index e40ed48..0764b6a 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -33,11 +33,7 @@ $(DefineConstants);ATOMIC_APPEND;HRESULTS - - $(DefineConstants);OS_MUTEX - - - + $(DefineConstants);OS_MUTEX From cbdd13e5323dd4479a10db4a213f590b9e65e38a Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 30 Jul 2020 23:04:25 -0700 Subject: [PATCH 10/13] Add More TargetFrameworks for Update References Cleanup References --- example/Sample/Sample.csproj | 11 +++-------- .../Serilog.Sinks.File.Tests.csproj | 17 ++++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/example/Sample/Sample.csproj b/example/Sample/Sample.csproj index e307db1..dd51d9a 100644 --- a/example/Sample/Sample.csproj +++ b/example/Sample/Sample.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.0;net47 + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 Sample Exe Sample @@ -11,11 +11,6 @@ - - - - - - + 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..9ac2a85 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -1,7 +1,8 @@ - + - net47;netcoreapp3.1 + + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 true Serilog.Sinks.File.Tests ../../assets/Serilog.snk @@ -17,16 +18,14 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - - From 4a634c4e515e101c5843d53ce147ff2b1740ad71 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Sun, 2 Aug 2020 23:36:38 -0700 Subject: [PATCH 11/13] Remove netcoreapp3.0 to use netstandard2.0 insted --- 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 0764b6a..3473e5a 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -4,7 +4,7 @@ Write Serilog events to text files in plain or JSON format. 5.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp3.0 + net45;netstandard1.3;netstandard2.0; true ../../assets/Serilog.snk true From a1ba60e92d3324d212436dd45fe6d391e4bf5147 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 22 Jun 2021 11:37:14 +1000 Subject: [PATCH 12/13] Unpin the assembly version; fixes #135 --- src/Serilog.Sinks.File/Properties/AssemblyInfo.cs | 2 -- src/Serilog.Sinks.File/Serilog.Sinks.File.csproj | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Serilog.Sinks.File/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.File/Properties/AssemblyInfo.cs index 0d5d620..93017cb 100644 --- a/src/Serilog.Sinks.File/Properties/AssemblyInfo.cs +++ b/src/Serilog.Sinks.File/Properties/AssemblyInfo.cs @@ -2,8 +2,6 @@ using System.Reflection; using System.Runtime.CompilerServices; -[assembly: AssemblyVersion("2.0.0.0")] - [assembly: CLSCompliant(true)] [assembly: InternalsVisibleTo("Serilog.Sinks.File.Tests, PublicKey=" + diff --git a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj index b2846b9..493078d 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -16,7 +16,6 @@ Apache-2.0 https://github.com/serilog/serilog-sinks-file git - false Serilog true true From 6f4375147895abba5c72d9b6410e0c1f7e9d5f3b Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 22 Jun 2021 12:07:53 +1000 Subject: [PATCH 13/13] Remove matching test --- test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs index d295dfc..fb9c9bf 100644 --- a/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs +++ b/test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs @@ -3,7 +3,6 @@ using System.IO; using System.IO.Compression; using System.Linq; -using System.Reflection; using Xunit; using Serilog.Events; using Serilog.Sinks.File.Tests.Support; @@ -128,7 +127,7 @@ public void WhenRetentionCountAndTimeIsSetOldFilesAreDeletedByCount() Assert.True(System.IO.File.Exists(files[2])); }); } - + [Fact] public void WhenRetentionCountAndArchivingHookIsSetOldFilesAreCopiedAndOriginalDeleted() { @@ -261,13 +260,6 @@ public void IfTheLogFolderDoesNotExistItWillBeCreated() } } - [Fact] - public void AssemblyVersionIsFixedAt200() - { - var assembly = typeof(FileLoggerConfigurationExtensions).GetTypeInfo().Assembly; - Assert.Equal("2.0.0.0", assembly.GetName().Version.ToString(4)); - } - static void TestRollingEventSequence(params LogEvent[] events) { TestRollingEventSequence(