From 8c27ae5fca5cb31460e849ed9693aad219e6086d Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Thu, 17 Jun 2021 18:15:19 +0200 Subject: [PATCH 1/4] Switch to Microsoft.Extensions.Logging.Abstractions Don't abuse the transitive dependency on DependencyInjection --- Directory.Build.props | 5 ++ Directory.Packages.props | 14 +++++ build.sh | 2 +- global.json | 7 --- samples/Sample/Sample.csproj | 8 +-- serilog-extensions-logging.sln | 6 +++ .../Logging/SerilogLoggerProvider.cs | 1 - .../Serilog.Extensions.Logging.csproj | 8 +-- .../SerilogLoggingBuilderExtensions.cs | 54 ------------------- ...rilog.Extensions.Logging.Benchmarks.csproj | 10 ++-- .../Serilog.Extensions.Logging.Tests.csproj | 8 +-- 11 files changed, 43 insertions(+), 80 deletions(-) create mode 100644 Directory.Build.props create mode 100644 Directory.Packages.props delete mode 100644 global.json delete mode 100644 src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..e4951e3 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,5 @@ + + + true + + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..141b147 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.sh b/build.sh index 6d1ff38..73b51d3 100644 --- a/build.sh +++ b/build.sh @@ -8,5 +8,5 @@ for path in src/**/*.csproj; do done for path in test/*.Tests/*.csproj; do - dotnet test -f netcoreapp2.0 -c Release ${path} + dotnet test -c Release ${path} done \ No newline at end of file diff --git a/global.json b/global.json deleted file mode 100644 index e3bbb00..0000000 --- a/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "allowPrerelease": false, - "version": "3.1.100", - "rollForward": "latestFeature" - } -} diff --git a/samples/Sample/Sample.csproj b/samples/Sample/Sample.csproj index c557b8a..344101c 100644 --- a/samples/Sample/Sample.csproj +++ b/samples/Sample/Sample.csproj @@ -12,10 +12,10 @@ - - - - + + + + \ No newline at end of file diff --git a/serilog-extensions-logging.sln b/serilog-extensions-logging.sln index c53414c..9b66c3c 100644 --- a/serilog-extensions-logging.sln +++ b/serilog-extensions-logging.sln @@ -26,6 +26,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Logging.Benchmarks", "test\Serilog.Extensions.Logging.Benchmarks\Serilog.Extensions.Logging.Benchmarks.csproj", "{6D5986FF-EECD-4E75-8BC6-A5F78AB549B2}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{137C37F5-9F88-4B53-90C5-5C66589FE067}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs index d51c2c0..efdede3 100644 --- a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs +++ b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs @@ -15,7 +15,6 @@ namespace Serilog.Extensions.Logging /// /// An that pipes events through Serilog. /// - [ProviderAlias("Serilog")] public class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher { internal const string OriginalFormatPropertyName = "{OriginalFormat}"; diff --git a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj index a67b319..9fa5452 100644 --- a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj +++ b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj @@ -1,10 +1,10 @@ - + Low-level Serilog provider for Microsoft.Extensions.Logging 3.0.2 Microsoft;Serilog Contributors - netstandard2.0 + netstandard2.0 true true Serilog.Extensions.Logging @@ -27,8 +27,8 @@ - - + + diff --git a/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs b/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs deleted file mode 100644 index 2cf0008..0000000 --- a/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017 Serilog Contributors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Serilog.Extensions.Logging; - -namespace Serilog -{ - /// - /// Extends with Serilog configuration methods. - /// - public static class SerilogLoggingBuilderExtensions - { - /// - /// Add Serilog to the logging pipeline. - /// - /// The to add logging provider to. - /// The Serilog logger; if not supplied, the static will be used. - /// When true, dispose when the framework disposes the provider. If the - /// logger is not specified but is true, the method will be - /// called on the static class instead. - /// Reference to the supplied . - public static ILoggingBuilder AddSerilog(this ILoggingBuilder builder, ILogger logger = null, bool dispose = false) - { - if (builder == null) throw new ArgumentNullException(nameof(builder)); - - if (dispose) - { - builder.Services.AddSingleton(services => new SerilogLoggerProvider(logger, true)); - } - else - { - builder.AddProvider(new SerilogLoggerProvider(logger)); - } - - builder.AddFilter(null, LogLevel.Trace); - - return builder; - } - } -} diff --git a/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj b/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj index 7840f21..9e90d8f 100644 --- a/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj +++ b/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + net5.0 true @@ -10,13 +10,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj index e1a144a..f6b10ec 100644 --- a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj +++ b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0;net472 + net5.0 Serilog.Extensions.Logging.Tests ../../assets/Serilog.snk true @@ -15,9 +15,9 @@ - - - + + + From e5decd4133908be0d41228066149a78e399cb713 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Fri, 18 Jun 2021 09:18:46 +0200 Subject: [PATCH 2/4] Add separate DependencyInjection extensions library --- serilog-extensions-logging.sln | 7 +++ .../AliasedSerilogLoggerProvider.cs | 30 +++++++++++ ...rilog.Extensions.Logging.Extensions.csproj | 37 +++++++++++++ .../SerilogLogginBuilderExtensions.cs | 54 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/Serilog.Extensions.Logging.Extensions/AliasedSerilogLoggerProvider.cs create mode 100644 src/Serilog.Extensions.Logging.Extensions/Serilog.Extensions.Logging.Extensions.csproj create mode 100644 src/Serilog.Extensions.Logging.Extensions/SerilogLogginBuilderExtensions.cs diff --git a/serilog-extensions-logging.sln b/serilog-extensions-logging.sln index 9b66c3c..c8b2709 100644 --- a/serilog-extensions-logging.sln +++ b/serilog-extensions-logging.sln @@ -32,6 +32,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution Directory.Packages.props = Directory.Packages.props EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging.Extensions", "src\Serilog.Extensions.Logging.Extensions\Serilog.Extensions.Logging.Extensions.csproj", "{8D7B8EAB-18F7-439F-A877-C6BD3070BCC0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,6 +56,10 @@ Global {6D5986FF-EECD-4E75-8BC6-A5F78AB549B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D5986FF-EECD-4E75-8BC6-A5F78AB549B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D5986FF-EECD-4E75-8BC6-A5F78AB549B2}.Release|Any CPU.Build.0 = Release|Any CPU + {8D7B8EAB-18F7-439F-A877-C6BD3070BCC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D7B8EAB-18F7-439F-A877-C6BD3070BCC0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D7B8EAB-18F7-439F-A877-C6BD3070BCC0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D7B8EAB-18F7-439F-A877-C6BD3070BCC0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,6 +69,7 @@ Global {37EADF84-5E41-4224-A194-1E3299DCD0B8} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1} {65357FBC-9BC4-466D-B621-1C3A19BC2A78} = {F2407211-6043-439C-8E06-3641634332E7} {6D5986FF-EECD-4E75-8BC6-A5F78AB549B2} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1} + {8D7B8EAB-18F7-439F-A877-C6BD3070BCC0} = {A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {811E61C5-3871-4633-AFAE-B35B619C8A10} diff --git a/src/Serilog.Extensions.Logging.Extensions/AliasedSerilogLoggerProvider.cs b/src/Serilog.Extensions.Logging.Extensions/AliasedSerilogLoggerProvider.cs new file mode 100644 index 0000000..5eed9fb --- /dev/null +++ b/src/Serilog.Extensions.Logging.Extensions/AliasedSerilogLoggerProvider.cs @@ -0,0 +1,30 @@ +// Copyright 2017 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Microsoft.Extensions.Logging; +using Serilog.Extensions.Logging; + +namespace Serilog +{ + /// + [ProviderAlias("Serilog")] + public class AliasedSerilogLoggerProvider : SerilogLoggerProvider + { + /// + public AliasedSerilogLoggerProvider(ILogger logger = null, bool dispose = false) + : base(logger, dispose) + { + } + } +} \ No newline at end of file diff --git a/src/Serilog.Extensions.Logging.Extensions/Serilog.Extensions.Logging.Extensions.csproj b/src/Serilog.Extensions.Logging.Extensions/Serilog.Extensions.Logging.Extensions.csproj new file mode 100644 index 0000000..025de02 --- /dev/null +++ b/src/Serilog.Extensions.Logging.Extensions/Serilog.Extensions.Logging.Extensions.csproj @@ -0,0 +1,37 @@ + + + + Low-level Serilog provider for Microsoft.Extensions.Logging + 3.0.2 + Microsoft;Serilog Contributors + netstandard2.0 + true + true + Serilog.Extensions.Logging.Extensions + ../../assets/Serilog.snk + true + true + Serilog.Extensions.Logging.Extensions + serilog;Microsoft.Extensions.Logging + serilog-extension-nuget.png + https://github.com/serilog/serilog-extensions-logging + Apache-2.0 + https://github.com/serilog/serilog-extensions-logging + git + false + Serilog + + + + + + + + + + + + + + + diff --git a/src/Serilog.Extensions.Logging.Extensions/SerilogLogginBuilderExtensions.cs b/src/Serilog.Extensions.Logging.Extensions/SerilogLogginBuilderExtensions.cs new file mode 100644 index 0000000..b98b2c7 --- /dev/null +++ b/src/Serilog.Extensions.Logging.Extensions/SerilogLogginBuilderExtensions.cs @@ -0,0 +1,54 @@ +// Copyright 2017 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog.Extensions.Logging; + +namespace Serilog +{ + /// + /// Extends with Serilog configuration methods. + /// + public static class SerilogLoggingBuilderExtensions + { + /// + /// Add Serilog to the logging pipeline. + /// + /// The to add logging provider to. + /// The Serilog logger; if not supplied, the static will be used. + /// When true, dispose when the framework disposes the provider. If the + /// logger is not specified but is true, the method will be + /// called on the static class instead. + /// Reference to the supplied . + public static ILoggingBuilder AddSerilog(this ILoggingBuilder builder, ILogger logger = null, bool dispose = false) + { + if (builder == null) throw new ArgumentNullException(nameof(builder)); + + if (dispose) + { + builder.Services.AddSingleton(services => new AliasedSerilogLoggerProvider(logger, true)); + } + else + { + builder.AddProvider(new AliasedSerilogLoggerProvider(logger)); + } + + builder.AddFilter(null, LogLevel.Trace); + + return builder; + } + } +} \ No newline at end of file From e668a9622ba45c5d8cc375dd6ab1ed0d6927024a Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Fri, 18 Jun 2021 09:18:52 +0200 Subject: [PATCH 3/4] Enable sourcelink --- Directory.Build.props | 11 +++++++++++ Directory.Packages.props | 1 + 2 files changed, 12 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index e4951e3..a8bfd4c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,4 +2,15 @@ true + + + true + true + true + snupkg + + + + + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 141b147..7fa14b9 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,5 +10,6 @@ + \ No newline at end of file From 121132b42d468e937864f5503c934ab46e3f7188 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Fri, 18 Jun 2021 09:27:48 +0200 Subject: [PATCH 4/4] Include snupkg --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 628e491..9b1c1b8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,18 +7,18 @@ build_script: - ps: ./Build.ps1 test: off artifacts: -- path: artifacts/Serilog.*.nupkg +- path: artifacts/Serilog.*nupkg deploy: - provider: NuGet api_key: secure: kYR3BYzJm3wSFbFjPhgTzuDHHcE8ApoNUmHvJvunWZ39nyrqVk6J6srjzYVQ7/gX - skip_symbols: true + skip_symbols: false on: branch: /^(master|dev)$/ - provider: GitHub auth_token: secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX - artifact: /Serilog.*\.nupkg/ + artifact: /Serilog.*nupkg/ tag: v$(appveyor_build_version) on: branch: master