diff --git a/appveyor.yml b/appveyor.yml index e72de6c..ad4973c 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 diff --git a/example/Sample/Sample.csproj b/example/Sample/Sample.csproj index e307db1..4915e19 100644 --- a/example/Sample/Sample.csproj +++ b/example/Sample/Sample.csproj @@ -1,7 +1,9 @@ - + - netcoreapp2.0;net47 + net48;net5.0 + 8.0 + enable Sample Exe Sample @@ -12,10 +14,5 @@ - - - - - diff --git a/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs index 54b20b4..3518322 100644 --- a/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs @@ -253,17 +253,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)); @@ -324,15 +324,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)); @@ -443,10 +443,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)); @@ -487,9 +487,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)); @@ -500,21 +500,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/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..6db7104 100644 --- a/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj +++ b/src/Serilog.Sinks.File/Serilog.Sinks.File.csproj @@ -4,7 +4,9 @@ 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 + 8.0 + enable true ../../assets/Serilog.snk true @@ -16,7 +18,6 @@ Apache-2.0 https://github.com/serilog/serilog-sinks-file git - false Serilog true true @@ -34,26 +35,12 @@ $(DefineConstants);ATOMIC_APPEND;HRESULTS - + $(DefineConstants);OS_MUTEX - - $(DefineConstants);OS_MUTEX - - - - - - - - - - - - - + diff --git a/src/Serilog.Sinks.File/Sinks/File/FileSink.cs b/src/Serilog.Sinks.File/Sinks/File/FileSink.cs index dd83a3f..76ada0b 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. @@ -54,7 +54,7 @@ public sealed class FileSink : IFileSink, IDisposable /// The caller does not have the required permission to access the /// Invalid [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) { } @@ -64,9 +64,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."); @@ -105,7 +105,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 0eb4463..dccb802 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)); @@ -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 723058e..6cf55cb 100644 --- a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs +++ b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.AtomicAppend.cs @@ -58,7 +58,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable /// When is too long /// The caller does not have the required permission to access the /// Invalid - 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/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs index 2aad6a2..b8a07db 100644 --- a/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs +++ b/src/Serilog.Sinks.File/Sinks/File/SharedFileSink.OSMutex.cs @@ -57,7 +57,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable /// When is too long /// The caller does not have the required permission to access the /// Invalid - 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..9232bde 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() { @@ -242,7 +241,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 { @@ -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( @@ -278,7 +270,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/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/Serilog.Sinks.File.Tests.csproj b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj index fcf2880..90ef89d 100644 --- a/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj +++ b/test/Serilog.Sinks.File.Tests/Serilog.Sinks.File.Tests.csproj @@ -1,15 +1,16 @@ - + - net47;netcoreapp3.1 + + net48;net5.0 + 8.0 + enable true Serilog.Sinks.File.Tests ../../assets/Serilog.snk true true true - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - 1.0.4 @@ -17,16 +18,14 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - - diff --git a/test/Serilog.Sinks.File.Tests/Support/CaptureFilePathHook.cs b/test/Serilog.Sinks.File.Tests/Support/CaptureFilePathHook.cs index a116f95..65857d1 100644 --- a/test/Serilog.Sinks.File.Tests/Support/CaptureFilePathHook.cs +++ b/test/Serilog.Sinks.File.Tests/Support/CaptureFilePathHook.cs @@ -9,7 +9,7 @@ namespace Serilog.Sinks.File.Tests.Support /// class CaptureFilePathHook : FileLifecycleHooks { - public string Path { get; private set; } + public string? Path { get; private set; } public override Stream OnFileOpened(string path, Stream _, Encoding __) { 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/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(); } 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")); }