Skip to content

Add support C# 8 nullable reference types #166

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

Merged
merged 18 commits into from
Jun 22, 2021
Merged
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
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions example/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net47</TargetFrameworks>
<TargetFrameworks>net48;net5.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<AssemblyName>Sample</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Sample</PackageId>
Expand All @@ -12,10 +14,5 @@
<ProjectReference Include="..\..\src\Serilog.Sinks.File\Serilog.Sinks.File.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>

36 changes: 18 additions & 18 deletions src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -500,21 +500,21 @@ public static LoggerConfiguration File(
}

static LoggerConfiguration ConfigureFile(
this Func<ILogEventSink, LogEventLevel, LoggingLevelSwitch, LoggerConfiguration> addSink,
this Func<ILogEventSink, LogEventLevel, LoggingLevelSwitch?, LoggerConfiguration> 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));
Expand Down
2 changes: 0 additions & 2 deletions src/Serilog.Sinks.File/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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=" +
Expand Down
23 changes: 5 additions & 18 deletions src/Serilog.Sinks.File/Serilog.Sinks.File.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<Description>Write Serilog events to text files in plain or JSON format.</Description>
<VersionPrefix>5.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -16,7 +18,6 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-file</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<RootNamespace>Serilog</RootNamespace>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFrameworkReferences Condition=" '$(TargetFramework)' == 'netstandard1.3' ">true</DisableImplicitFrameworkReferences>
Expand All @@ -34,26 +35,12 @@
<DefineConstants>$(DefineConstants);ATOMIC_APPEND;HRESULTS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PropertyGroup Condition=" '$(TargetFramework)' != 'net45' ">
<DefineConstants>$(DefineConstants);OS_MUTEX</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp3.0' ">
<DefineConstants>$(DefineConstants);OS_MUTEX</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.IO" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
<PackageReference Include="System.Threading.Timer" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\assets\serilog-sink-nuget.png" Pack="true" Visible="false" PackagePath="images\icon.png" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Serilog.Sinks.File/Sinks/File/FileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>Construct a <see cref="FileSink"/>.</summary>
/// <param name="path">Path to the file.</param>
Expand All @@ -54,7 +54,7 @@ public sealed class FileSink : IFileSink, IDisposable
/// <exception cref="UnauthorizedAccessException">The caller does not have the required permission to access the <paramref name="path"/></exception>
/// <exception cref="ArgumentException">Invalid <paramref name="path"/></exception>
[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)
{
}
Expand All @@ -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.");
Expand Down Expand Up @@ -105,7 +105,7 @@ bool IFileSink.EmitOrOverflow(LogEvent logEvent)
{
if (_fileSizeLimitBytes != null)
{
if (_countingStreamWrapper.CountedLength >= _fileSizeLimitBytes.Value)
if (_countingStreamWrapper!.CountedLength >= _fileSizeLimitBytes.Value)
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) { }
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable
/// <exception cref="PathTooLongException">When <paramref name="path"/> is too long</exception>
/// <exception cref="UnauthorizedAccessException">The caller does not have the required permission to access the <paramref name="path"/></exception>
/// <exception cref="ArgumentException">Invalid <paramref name="path"/></exception>
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public sealed class SharedFileSink : IFileSink, IDisposable
/// <exception cref="PathTooLongException">When <paramref name="path"/> is too long</exception>
/// <exception cref="UnauthorizedAccessException">The caller does not have the required permission to access the <paramref name="path"/></exception>
/// <exception cref="ArgumentException">Invalid <paramref name="path"/></exception>
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)
Expand Down
Loading