Skip to content
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

Add .NET 6 and C# 10 Support #419

Merged
merged 8 commits into from
Nov 9, 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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ jobs:
with:
lfs: true
fetch-depth: 0
- name: "Install .NET Core 3.1 SDK"
uses: actions/[email protected]
with:
dotnet-version: "3.1.x"
- name: "Install .NET Core 5.0 SDK"
uses: actions/[email protected]
with:
dotnet-version: "5.0.x"
- name: "Install .NET Core SDK"
uses: actions/[email protected]
- name: "Dotnet Tool Restore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Serilog.Exceptions.Benchmark
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.Net50)]
public class DestructuringBenchmark
{
private readonly ReflectionBasedDestructurer reflectionBasedDestructurer = new(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public ExceptionPropertiesBag(Exception exception, IExceptionPropertyFilter? fil

public void AddProperty(string key, object? value)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(key);
#else
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
#endif

if (this.resultsCollected)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup Label="Build">
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net472</TargetFrameworks>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -18,7 +18,7 @@
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>

<ItemGroup Label="Package References (.NET)" Condition=" '$(TargetFramework)' == 'net5.0' ">
<ItemGroup Label="Package References (.NET)" Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/RehanSaeed/Serilog.Exceptions</PackageProjectUrl>
<PackageIcon>Icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/RehanSaeed/Serilog.Exceptions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>https://github.com/RehanSaeed/Serilog.Exceptions/releases</PackageReleaseNotes>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Serilog.Exceptions Banner](Images/Banner.png)
![Serilog.Exceptions Banner](https://media.githubusercontent.com/media/RehanSaeed/Serilog.Exceptions/main/Images/Banner.png)

[![Serilog.Exceptions NuGet Package](https://img.shields.io/nuget/v/Serilog.Exceptions.svg)](https://www.nuget.org/packages/Serilog.Exceptions/) [![Serilog.Exceptions package in serilog-exceptions feed in Azure Artifacts](https://feeds.dev.azure.com/serilog-exceptions/_apis/public/Packaging/Feeds/8479813c-da6b-4677-b40d-78df8725dc9c/Packages/212043f6-5fe5-4c79-949e-162156b89894/Badge)](https://dev.azure.com/serilog-exceptions/Serilog.Exceptions/_packaging?_a=package&feed=8479813c-da6b-4677-b40d-78df8725dc9c&package=212043f6-5fe5-4c79-949e-162156b89894&preferRelease=true) [![Serilog.Exceptions NuGet Package Downloads](https://img.shields.io/nuget/dt/Serilog.Exceptions)](https://www.nuget.org/packages/Serilog.Exceptions) [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/RehanSaeedUK) [![Twitter Follow](https://img.shields.io/twitter/follow/rehansaeeduk.svg?style=social&label=Follow)](https://twitter.com/RehanSaeedUK)

Expand Down Expand Up @@ -262,7 +262,7 @@ Filtering for other scenarios is also supported:

## Contributions and Thanks

Please view the [contributing guide](/.github/CONTRIBUTING.md) for more information.
Please view the [contributing guide](https://github.com/RehanSaeed/Serilog.Exceptions/blob/main/.github/CONTRIBUTING.md) for more information.

- [304NotModified](https://github.com/304NotModified) - Added Markdown syntax highlighting.
- [joelweiss](https://github.com/joelweiss) - Added Entity Framework Core destructurers.
Expand Down
1 change: 1 addition & 0 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<ItemGroup Label="Files">
<None Include="..\..\Images\Icon.png" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand All @@ -14,7 +14,11 @@
<ProjectReference Include="..\Serilog.Exceptions\Serilog.Exceptions.csproj" />
</ItemGroup>

<ItemGroup Label="Package References">
<ItemGroup Label="Package References (.NET 6)" Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
</ItemGroup>

<ItemGroup Label="Package References (.NET 5)" Condition="'$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;net472;net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ public override void Destructure(Exception exception, IExceptionPropertiesBag pr
{
// Argument checks are usually done in <see cref="ExceptionDestructurer.Destructure"/>
// but as we didn't call this method we need to do the checks here.
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(exception);
ArgumentNullException.ThrowIfNull(propertiesBag);
ArgumentNullException.ThrowIfNull(destructureException);
#else
if (exception is null)
{
throw new ArgumentNullException(nameof(propertiesBag));
throw new ArgumentNullException(nameof(exception));
}

if (propertiesBag is null)
Expand All @@ -54,6 +59,7 @@ public override void Destructure(Exception exception, IExceptionPropertiesBag pr
{
throw new ArgumentNullException(nameof(destructureException));
}
#endif
}

#pragma warning disable CA1062 // Validate arguments of public methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;net472;net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net5.0;netstandard2.0;netstandard1.6;netstandard1.3;net472;net461</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;netstandard1.3;net472;net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand All @@ -14,7 +14,7 @@
<ProjectReference Include="..\..\Source\Serilog.Exceptions\Serilog.Exceptions.csproj" />
</ItemGroup>

<ItemGroup Label="Package References (.NET)" Condition="'$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard1.6' OR '$(TargetFramework)' == 'netstandard1.3' ">
<ItemGroup Label="Package References (.NET)" Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>

Expand Down
8 changes: 8 additions & 0 deletions Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ public class DestructuringOptionsBuilder : IDestructuringOptions
/// <returns>Options builder for method chaining.</returns>
public DestructuringOptionsBuilder WithDestructurers(IEnumerable<IExceptionDestructurer> destructurers)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(destructurers);
#else
if (destructurers is null)
{
throw new ArgumentNullException(nameof(destructurers));
}
#endif

this.destructurers.AddRange(destructurers);
return this;
Expand Down Expand Up @@ -127,10 +131,14 @@ public DestructuringOptionsBuilder WithIgnoreStackTraceAndTargetSiteExceptionFil
/// <exception cref="ArgumentException">Name cannot be null or empty.</exception>
public DestructuringOptionsBuilder WithRootName(string rootName)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(rootName);
#else
if (rootName is null)
{
throw new ArgumentNullException(nameof(rootName));
}
#endif

if (rootName.Length == 0)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/Serilog.Exceptions/Core/ExceptionEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public ExceptionEnricher(IDestructuringOptions destructuringOptions)
/// <param name="propertyFactory">The property factory.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logEvent);
ArgumentNullException.ThrowIfNull(propertyFactory);
#else
if (logEvent is null)
{
throw new ArgumentNullException(nameof(logEvent));
Expand All @@ -59,6 +63,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
throw new ArgumentNullException(nameof(propertyFactory));
}
#endif

if (logEvent.Exception is not null)
{
Expand Down
9 changes: 6 additions & 3 deletions Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ public ExceptionPropertiesBag(Exception exception, IExceptionPropertyFilter? fil
/// <inheritdoc />
public void AddProperty(string key, object? value)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(key);
#else
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
#endif

if (this.resultsCollected)
{
Expand Down Expand Up @@ -78,7 +82,7 @@ public void AddProperty(string key, object? value)
/// </summary>
private void AddPairToProperties(string key, object? value)
{
#if NET5_0
#if NET5_0_OR_GREATER
var i = 0;
while (!this.properties.TryAdd(key, value) && i < AcceptableNumberOfSameNameProperties)
{
Expand All @@ -92,7 +96,7 @@ private void AddPairToProperties(string key, object? value)
#endif
}

#if !NET5_0
#if !NET5_0_OR_GREATER
private string MakeSureKeyIsUnique(string key)
{
var i = 0;
Expand All @@ -105,6 +109,5 @@ private string MakeSureKeyIsUnique(string key)
return key;
}
#endif

}
}
Loading