From f6c58ef6ae1a59fd182406d9798683a1658e6766 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Mon, 23 Nov 2020 23:42:27 +0100 Subject: [PATCH 01/12] Added NLogProviderOptions.IncludeActivtyIdsWithBeginScope --- .../NLog.Extensions.Hosting.csproj | 6 +- .../Logging/ActivityExtensions.cs | 44 +++++++++++ .../Logging/NLogBeginScopeParser.cs | 79 ++++++++++++++++++- .../Logging/NLogProviderOptions.cs | 13 +++ .../NLog.Extensions.Logging.csproj | 11 ++- 5 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 src/NLog.Extensions.Logging/Logging/ActivityExtensions.cs diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj index 8320a0e4..c6b1f64c 100644 --- a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netcoreapp3.0 + netstandard2.0;netcoreapp3.0;net50 Full true true @@ -41,6 +41,10 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN + + + + diff --git a/src/NLog.Extensions.Logging/Logging/ActivityExtensions.cs b/src/NLog.Extensions.Logging/Logging/ActivityExtensions.cs new file mode 100644 index 00000000..eab2bbc6 --- /dev/null +++ b/src/NLog.Extensions.Logging/Logging/ActivityExtensions.cs @@ -0,0 +1,44 @@ +#if NET5_0 + +using System.Diagnostics; + +namespace NLog.Extensions.Logging +{ + /// + /// Helpers for getting the right values from Activity no matter the format (w3c or hierarchical) + /// + internal static class ActivityExtensions + { + public static string GetSpanId(this Activity activity) + { + return activity.IdFormat switch + { + ActivityIdFormat.Hierarchical => activity.Id, + ActivityIdFormat.W3C => activity.SpanId.ToHexString(), + _ => null, + } ?? string.Empty; + } + + public static string GetTraceId(this Activity activity) + { + return activity.IdFormat switch + { + ActivityIdFormat.Hierarchical => activity.RootId, + ActivityIdFormat.W3C => activity.TraceId.ToHexString(), + _ => null, + } ?? string.Empty; + } + + public static string GetParentId(this Activity activity) + { + return activity.IdFormat switch + { + ActivityIdFormat.Hierarchical => activity.ParentId, + ActivityIdFormat.W3C => activity.ParentSpanId.ToHexString(), + _ => null, + } ?? string.Empty; + } + } +} + +#endif \ No newline at end of file diff --git a/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs b/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs index 8dd0db6c..079587f3 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs @@ -31,7 +31,7 @@ public IDisposable ParseBeginScope(T state) { if (state is IReadOnlyList> scopePropertyList) { - return ScopeProperties.CaptureScopeProperties(scopePropertyList); + return ScopeProperties.CaptureScopeProperties(scopePropertyList, _options.IncludeActivtyIdsWithBeginScope); } if (!(state is string)) @@ -90,18 +90,89 @@ private static IDisposable CreateScopeProperties(object scopeObject, IReadOnlyLi return NestedDiagnosticsLogicalContext.Push(scopeObject); } - public static IDisposable CaptureScopeProperties(IReadOnlyList> scopePropertyList) + public static IDisposable CaptureScopeProperties(IReadOnlyList> scopePropertyList, bool includeActivtyIdsWithBeginScope) { object scopeObject = scopePropertyList; - if (scopePropertyList.Count > 0 && NLogLogger.OriginalFormatPropertyName.Equals(scopePropertyList[scopePropertyList.Count - 1].Key)) + if (scopePropertyList.Count > 0) { - scopePropertyList = ExcludeOriginalFormatProperty(scopePropertyList); + if (NLogLogger.OriginalFormatPropertyName.Equals(scopePropertyList[scopePropertyList.Count - 1].Key)) + { + scopePropertyList = ExcludeOriginalFormatProperty(scopePropertyList); + } + else if (includeActivtyIdsWithBeginScope && "RequestId".Equals(scopePropertyList[0].Key)) + { + scopePropertyList = IncludeActivityIdsProperties(scopePropertyList); + } } return CreateScopeProperties(scopeObject, scopePropertyList); } +#if !NET5_0 + private static IReadOnlyList> IncludeActivityIdsProperties(IReadOnlyList> scopePropertyList) + { + return scopePropertyList; + } +#else + private static IReadOnlyList> IncludeActivityIdsProperties(IReadOnlyList> scopePropertyList) + { + var activty = System.Diagnostics.Activity.Current; + if (activty != null) + return new ScopePropertiesWithActivityIds(scopePropertyList, activty); + else + return scopePropertyList; + } + + private class ScopePropertiesWithActivityIds : IReadOnlyList> + { + private readonly IReadOnlyList> _originalPropertyList; + private readonly System.Diagnostics.Activity _currentActivity; + + public ScopePropertiesWithActivityIds(IReadOnlyList> originalPropertyList, System.Diagnostics.Activity currentActivity) + { + _originalPropertyList = originalPropertyList; + _currentActivity = currentActivity; + } + + public KeyValuePair this[int index] + { + get + { + int offset = index - _originalPropertyList.Count; + if (offset < 0) + { + return _originalPropertyList[index]; + } + else + { + switch (offset) + { + case 0: return new KeyValuePair(nameof(_currentActivity.SpanId), _currentActivity.GetSpanId()); + case 1: return new KeyValuePair(nameof(_currentActivity.TraceId), _currentActivity.GetTraceId()); + case 2: return new KeyValuePair(nameof(_currentActivity.ParentId), _currentActivity.GetParentId()); + } + } + + throw new ArgumentOutOfRangeException(nameof(index)); + } + } + + public int Count => _originalPropertyList.Count + 3; + + public IEnumerator> GetEnumerator() + { + for (int i = 0; i < Count; ++i) + yield return this[i]; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)_originalPropertyList).GetEnumerator(); + } + } +#endif + private static IReadOnlyList> ExcludeOriginalFormatProperty(IReadOnlyList> scopePropertyList) { if (scopePropertyList.Count == 2 && !NLogLogger.OriginalFormatPropertyName.Equals(scopePropertyList[0].Key)) diff --git a/src/NLog.Extensions.Logging/Logging/NLogProviderOptions.cs b/src/NLog.Extensions.Logging/Logging/NLogProviderOptions.cs index 1354271d..c1185a17 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogProviderOptions.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogProviderOptions.cs @@ -43,6 +43,19 @@ public class NLogProviderOptions /// public bool ShutdownOnDispose { get; set; } +#if NET5_0 + /// + /// Automatically include , and + /// + /// For Net5.0 where these properties are no longer included by default for performance reasons +#else + /// + /// Automatically include Activity.SpanId, Activity.TraceId and Activity.ParentId. + /// + /// For Net5.0 where these properties are no longer included by default for performance reasons +#endif + public bool IncludeActivtyIdsWithBeginScope { get; set; } + /// Initializes a new instance NLogProviderOptions with default values. public NLogProviderOptions() { diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index e99b104c..a070fa46 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -2,7 +2,7 @@ PackageReference - net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0 + net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net50 Full true true @@ -65,6 +65,10 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN NLog.Extensions.Logging for .NET Core 3 $(DefineConstants);NETSTANDARD + + NLog.Extensions.Logging for .NET 5.0 + $(DefineConstants);NETSTANDARD + @@ -96,6 +100,11 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN + + + + + $(Title) latest From ef86f110a0cccc0fc4325c164d7f5ad7859acfae Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Mon, 23 Nov 2020 23:53:00 +0100 Subject: [PATCH 02/12] Fix build warnings about targetframeworks being out of support --- .../NLog.Extensions.Hosting.Tests.csproj | 2 +- .../NLog.Extensions.Logging.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj index b6709160..c8b374f9 100644 --- a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj +++ b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj @@ -2,7 +2,7 @@ PackageReference - netcoreapp2.0;netcoreapp3.0 + netcoreapp2.1;netcoreapp3.1 Library false full diff --git a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj index 76becd50..b766cf6b 100644 --- a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj +++ b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj @@ -3,7 +3,7 @@ PackageReference - netcoreapp1.1;netcoreapp2.0;netcoreapp3.0;net452;net461 + netcoreapp1.1;netcoreapp2.1;netcoreapp3.1;net452;net461 Library false Full From 638a59d4a533db8cb93b3803ea3d53854b116666 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Mon, 23 Nov 2020 23:55:25 +0100 Subject: [PATCH 03/12] Fix build warning about obsolete PackageLicenseUrl --- src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj | 2 +- src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj index c6b1f64c..1b209af3 100644 --- a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -15,7 +15,7 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.Web.AspNetCore https://github.com/NLog/NLog.Extensions.Logging - https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE + BSD-2-Clause https://nlog-project.org/NConfig.png https://github.com/NLog/NLog.Extensions.Logging.git git diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index a070fa46..231c7afc 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -27,7 +27,7 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.W Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD https://github.com/NLog/NLog.Extensions.Logging - https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE + BSD-2-Clause https://nlog-project.org/NConfig.png https://github.com/NLog/NLog.Extensions.Logging.git git From 87ceb87958bcbdda0851fc80b4568bdb5bd7bbbb Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Mon, 23 Nov 2020 23:58:45 +0100 Subject: [PATCH 04/12] Added net50 to build script --- build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index a3eaf36c..033769c0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -17,11 +17,11 @@ dotnet restore .\src\NLog.Extensions.Hosting\ if (-Not $LastExitCode -eq 0) { exit $LastExitCode } -msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net50"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal if (-Not $LastExitCode -eq 0) { exit $LastExitCode } -msbuild /t:Pack .\src\NLog.Extensions.Hosting\ /p:targetFrameworks='"netstandard2.0;netcoreapp3.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +msbuild /t:Pack .\src\NLog.Extensions.Hosting\ /p:targetFrameworks='"netstandard2.0;netcoreapp3.0;net50"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal if (-Not $LastExitCode -eq 0) { exit $LastExitCode } From f578f25862f4db6c25a0ca3cef5c5d07d1bc4be6 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 24 Nov 2020 00:01:59 +0100 Subject: [PATCH 05/12] Fix build-warning about PackageIconUrl being obsolete --- .../NLog.Extensions.Hosting.csproj | 10 +++++++++- .../NLog.Extensions.Logging.csproj | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj index 1b209af3..38cc027d 100644 --- a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -16,7 +16,7 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.Web.AspNetCore https://github.com/NLog/NLog.Extensions.Logging BSD-2-Clause - https://nlog-project.org/NConfig.png + N.png https://github.com/NLog/NLog.Extensions.Logging.git git NLog;Microsoft.Extensions.Hosting;log;logging;logfiles;netcore @@ -33,6 +33,14 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN latest + + + + + + + + diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 231c7afc..527fd9ab 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -28,7 +28,7 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN https://github.com/NLog/NLog.Extensions.Logging BSD-2-Clause - https://nlog-project.org/NConfig.png + N.png https://github.com/NLog/NLog.Extensions.Logging.git git @@ -38,6 +38,15 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN ..\NLog.snk true + + + + + + + + + NLog.Extensions.Logging for .NET Framework 4.6.1 true From a2f8d2c50ac231e079559f5e72809623564ccdfc Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 24 Nov 2020 00:08:42 +0100 Subject: [PATCH 06/12] Fix build warnings about targetframeworks being out of support --- .../NLog.Extensions.Hosting.Tests.csproj | 6 +++--- .../NLog.Extensions.Logging.Tests.csproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj index c8b374f9..c12579b4 100644 --- a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj +++ b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj @@ -15,12 +15,12 @@ latest - + - - + + diff --git a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj index b766cf6b..411f4771 100644 --- a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj +++ b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj @@ -31,11 +31,11 @@ - + - - + + From 5d5e8aafcbc9cdfd6c3a29541b8c1d968db528ec Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 24 Nov 2020 00:13:09 +0100 Subject: [PATCH 07/12] Update build scripts to not use targetframeworks being out of support --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6e64132f..f59b838a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,10 +22,10 @@ artifacts: test_script: - nuget.exe install OpenCover -ExcludeVersion -DependencyVersion Ignore - OpenCover\tools\OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp1.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.0 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.0 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.0 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.0 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.1 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.1 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - pip install codecov - codecov -f "coverage.xml" - ps: .\run-sonar.ps1 From 37fea09f0863855fac473e80386dd480a3674ffa Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 24 Nov 2020 13:25:46 +0100 Subject: [PATCH 08/12] Added NLogProviderOptions.IncludeActivtyIdsWithBeginScope (RequestPath validation) --- .../Extensions/ConfigureExtensions.cs | 13 +++++++++++++ .../Logging/NLogBeginScopeParser.cs | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs index a5b52638..e66fe1c5 100644 --- a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs +++ b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs @@ -84,6 +84,19 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder factory, IConfigurati return factory; } + /// + /// Enable NLog as logging provider for Microsoft Extension Logging + /// + /// + /// Configuration + /// NLog options + /// ILoggingBuilder for chaining + public static ILoggingBuilder AddNLog(this ILoggingBuilder factory, IConfiguration configuration, NLogProviderOptions options) + { + AddNLogLoggerProvider(factory.Services, configuration, options, CreateNLogLoggerProvider); + return factory; + } + /// /// Enable NLog as logging provider for Microsoft Extension Logging /// diff --git a/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs b/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs index 079587f3..185ee396 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs @@ -117,11 +117,14 @@ private static IReadOnlyList> IncludeActivityIdsPro #else private static IReadOnlyList> IncludeActivityIdsProperties(IReadOnlyList> scopePropertyList) { - var activty = System.Diagnostics.Activity.Current; - if (activty != null) - return new ScopePropertiesWithActivityIds(scopePropertyList, activty); - else - return scopePropertyList; + if (scopePropertyList.Count > 1 && "RequestPath".Equals(scopePropertyList[1].Key)) + { + var activty = System.Diagnostics.Activity.Current; + if (activty != null) + return new ScopePropertiesWithActivityIds(scopePropertyList, activty); + } + + return scopePropertyList; } private class ScopePropertiesWithActivityIds : IReadOnlyList> From 57aa1977dba4028e21aba635134d3e7536dbe5ef Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Tue, 29 Dec 2020 01:05:22 +0100 Subject: [PATCH 09/12] test for .NET 5 --- build.ps1 | 4 ++-- .../NLog.Extensions.Hosting.csproj | 4 ++-- .../NLog.Extensions.Logging.csproj | 22 +++++++++---------- .../NLog.Extensions.Hosting.Tests.csproj | 6 ++++- .../NLog.Extensions.Logging.Tests.csproj | 6 ++++- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/build.ps1 b/build.ps1 index 033769c0..bb895044 100644 --- a/build.ps1 +++ b/build.ps1 @@ -17,11 +17,11 @@ dotnet restore .\src\NLog.Extensions.Hosting\ if (-Not $LastExitCode -eq 0) { exit $LastExitCode } -msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net50"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net5.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal if (-Not $LastExitCode -eq 0) { exit $LastExitCode } -msbuild /t:Pack .\src\NLog.Extensions.Hosting\ /p:targetFrameworks='"netstandard2.0;netcoreapp3.0;net50"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +msbuild /t:Pack .\src\NLog.Extensions.Hosting\ /p:targetFrameworks='"netstandard2.0;netcoreapp3.0;net5.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal if (-Not $LastExitCode -eq 0) { exit $LastExitCode } diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj index b7f4cfe7..e5c25dc1 100644 --- a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netcoreapp3.0;net50 + netstandard2.0;netcoreapp3.0;net5.0 Full true true @@ -49,7 +49,7 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN - + diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 1247f844..65191706 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -2,7 +2,7 @@ PackageReference - net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net50 + net451;net461;netstandard1.3;netstandard1.5;netstandard2.0;netcoreapp3.0;net5.0 Full true true @@ -57,24 +57,24 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN $(DefineConstants);NETCORE1_0 - NLog.Extensions.Logging for NetStandard 1.3 + NLog.Extensions.Logging for .NET Standard 1.3 1.6.0 $(DefineConstants);NETCORE1_0;NETSTANDARD - NLog.Extensions.Logging for NetStandard 1.5 + NLog.Extensions.Logging for .NET Standard 1.5 1.6.0 $(DefineConstants);NETCORE1_0;NETSTANDARD - NLog.Extensions.Logging for NetStandard 2.0 + NLog.Extensions.Logging for .NET Standard 2.0 $(DefineConstants);NETSTANDARD NLog.Extensions.Logging for .NET Core 3 $(DefineConstants);NETSTANDARD - + NLog.Extensions.Logging for .NET 5.0 $(DefineConstants);NETSTANDARD @@ -104,22 +104,20 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN - + + + + + - - - - - - $(Title) latest diff --git a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj index c12579b4..2d58a731 100644 --- a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj +++ b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj @@ -2,7 +2,7 @@ PackageReference - netcoreapp2.1;netcoreapp3.1 + netcoreapp2.1;netcoreapp3.1;net5.0 Library false full @@ -23,6 +23,10 @@ + + + + diff --git a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj index 411f4771..ac161f2f 100644 --- a/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj +++ b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj @@ -3,7 +3,7 @@ PackageReference - netcoreapp1.1;netcoreapp2.1;netcoreapp3.1;net452;net461 + netcoreapp1.1;netcoreapp2.1;netcoreapp3.1;net452;net461;net5.0 Library false Full @@ -37,6 +37,10 @@ + + + + From b338fa5728e1299de1b887d32b5296d219f2cc39 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Tue, 29 Dec 2020 01:18:38 +0100 Subject: [PATCH 10/12] tests with opencover --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index f59b838a..dd4bab21 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,8 +24,11 @@ test_script: - OpenCover\tools\OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp1.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.1 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f net5.0 -c debug NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.1 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.1 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f net5.0 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - pip install codecov - pip install codecov - codecov -f "coverage.xml" - ps: .\run-sonar.ps1 From d393fc5d1d330ea5f3cdf9dab988382629a8726b Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Tue, 29 Dec 2020 01:22:39 +0100 Subject: [PATCH 11/12] fix duplicate in csproj --- .../NLog.Extensions.Hosting.csproj | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj index e5c25dc1..f4b7f5bf 100644 --- a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -33,14 +33,6 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN latest - - - - - - - - From 2a4738ff5fce0ede021eee0ef3be61af439629eb Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Tue, 29 Dec 2020 01:34:53 +0100 Subject: [PATCH 12/12] fix duplicate in csproj v2 --- src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 65191706..c04f6843 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -39,10 +39,6 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN true - - - -