Skip to content

Commit f52adfa

Browse files
committed
Add net6.0 target framework
It will be beneficial for [string interpolation][1] which is used extensively through the project. See [Are there benefits in producing a .NET 6.0 version of a .NET Standard 2.0 library?][1] on Stack Overflow. Also, run mutation tests _after_ creating the NuGet package to ensure that Serilog.Formatting.Log4Net.dll is not altered by Styker.NET. [1]: https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/#arrays-strings-spans [2]: https://stackoverflow.com/questions/70778797/are-there-benefits-in-producing-a-net-6-0-version-of-a-net-standard-2-0-librar/72266562#72266562
1 parent df0948b commit f52adfa

9 files changed

+468
-14
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ jobs:
7878
with:
7979
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
8080
coverage-reports: ${{ steps.dotnet-test.outputs.coverage-reports }}
81-
- name: Run mutation tests and upload report to Stryker dashboard
82-
if: matrix.os == 'ubuntu-latest' && env.STRYKER_DASHBOARD_API_KEY != ''
83-
run: |
84-
cd tests
85-
dotnet tool restore
86-
dotnet tool run dotnet-stryker --reporter dashboard --version ${GITHUB_REF##*/} --dashboard-api-key ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
8781
- name: Create NuGet package
8882
run: dotnet pack --no-build --output .
8983
id: dotnet-pack
@@ -93,6 +87,12 @@ jobs:
9387
with:
9488
name: ${{ steps.dotnet-pack.outputs.nupkg-filename }}
9589
path: ${{ steps.dotnet-pack.outputs.nupkg-filename }}
90+
- name: Run mutation tests and upload report to Stryker dashboard
91+
if: matrix.os == 'ubuntu-latest' && env.STRYKER_DASHBOARD_API_KEY != ''
92+
run: |
93+
cd tests
94+
dotnet tool restore
95+
dotnet tool run dotnet-stryker --reporter dashboard --version ${GITHUB_REF##*/} --dashboard-api-key ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
9696
- name: Retrieve tag message
9797
if: matrix.os == 'ubuntu-latest'
9898
run: |

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [Unreleased][unreleased]
7+
8+
- Add support for .NET 6. It will be beneficial for [string interpolation](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/#arrays-strings-spans) which is used extensively through the project. See [Are there benefits in producing a .NET 6.0 version of a .NET Standard 2.0 library?](https://stackoverflow.com/questions/70778797/are-there-benefits-in-producing-a-net-6-0-version-of-a-net-standard-2-0-librar/72266562#72266562) on Stack Overflow.
9+
610
## [1.0.0][1.0.0] - 2022-03-08
711

812
- First final version (i.e. non pre-release) which is identical to 1.0.0-rc.4
@@ -67,6 +71,7 @@ Still trying to figure out how to make everything fit together with [MinVer](htt
6771

6872
- Implement log4j compatibility mode.
6973

74+
[unreleased]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.0...HEAD
7075
[1.0.0]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.0-rc.4...1.0.0
7176
[1.0.0-rc.4]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.0-rc.3...1.0.0-rc.4
7277
[1.0.0-rc.3]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.0-rc.2...1.0.0-rc.3

src/Log4NetTextFormatter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ public void Format(LogEvent logEvent, TextWriter output)
9595
// That's why we write the event in a StringWriter then massage the output to remove the xmlns:log4j attribute to match log4j output.
9696
// The XML fragment becomes valid when surrounded by an external entity, see https://github.com/apache/log4j/blob/v1_2_17/src/main/java/org/apache/log4j/xml/XMLLayout.java#L31-L49
9797
const string log4JNamespaceAttribute = @" xmlns:log4j=""http://jakarta.apache.org/log4j/""";
98-
var xmlString = xmlWriterOutput.ToString();
98+
var xmlString = ((StringWriter)xmlWriterOutput).ToString();
9999
var i = xmlString.IndexOf(log4JNamespaceAttribute, StringComparison.Ordinal);
100+
#if NETSTANDARD2_0
100101
output.Write(xmlString.Substring(0, i));
101102
output.Write(xmlString.Substring(i + log4JNamespaceAttribute.Length));
103+
#else
104+
output.Write(xmlString.AsSpan(0, i));
105+
output.Write(xmlString.AsSpan(i + log4JNamespaceAttribute.Length));
106+
#endif
102107
}
103108
output.Write(_options.XmlWriterSettings.NewLineChars);
104109
}
@@ -401,7 +406,7 @@ private void WriteException(LogEvent logEvent, XmlWriter writer)
401406
{
402407
try
403408
{
404-
return _options.FormatException(exception);
409+
return (string?)_options.FormatException(exception);
405410
}
406411
catch (Exception formattingException)
407412
{

src/Serilog.Formatting.Log4Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<PropertyGroup Label="Compiling">

0 commit comments

Comments
 (0)