From e53192a3fbac914546a052cf7d690355ff84d81d Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 21 Sep 2020 15:44:36 +1000 Subject: [PATCH 1/9] Update Seq.Extensions.Logging.csproj --- src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj index 0ffd3fa..72a5a36 100644 --- a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj +++ b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj @@ -1,8 +1,8 @@ - + Add centralized structured log collection to ASP.NET Core apps with one line of code. - 5.0.0 + 5.0.1 Datalust and Contributors net462;netstandard2.0 true From 075d8895d43dd3150aff49c7266ff5e03888e311 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 27 Oct 2020 08:20:36 +1000 Subject: [PATCH 2/9] `master` -> `main` --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 489e6fb..2f75401 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,4 +12,4 @@ deploy: secure: 94298ksNMfJ2LkBV3Lw9o4JVzKvVPPMHF91p0XjsBhNWVeMX2NeROX4fpio6BsQy skip_symbols: true on: - branch: /^(master|dev)$/ + branch: /^(main|dev)$/ From 96ab8f8416f8369b7467b0e91f9f0b66d09b4802 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 27 Oct 2020 08:21:30 +1000 Subject: [PATCH 3/9] `master` -> `main` ... think that's all of them! --- Build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build.ps1 b/Build.ps1 index 9b2d878..fe080b5 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -11,7 +11,7 @@ if(Test-Path .\artifacts) { $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] echo "build: Version suffix is $suffix" From 627912f4946865f3ff0294b6f45157fd1f75d6a6 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 2 Dec 2020 13:12:59 +1000 Subject: [PATCH 4/9] Fix screenshot in README [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7128444..f7b5b93 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ For an example, see [the _dotnetconf_ deep dive session](https://channel9.msdn.com/Events/dotnetConf/2016/ASPNET-Core--deep-dive-on-building-a-real-website-with-todays-bits). -![Screenshot](https://github.com/datalust/seq-extensions-logging/blob/master/asset/screenshot.png?raw=true) +![Screenshot](https://raw.githubusercontent.com/datalust/seq-extensions-logging/dev/asset/screenshot.png) This package makes it a one-liner to configure ASP.NET Core logging with Seq. From 5c20021a59e11c5a68ee68e89e0c6a9d2ce2d320 Mon Sep 17 00:00:00 2001 From: Sergey Komisarchik Date: Wed, 6 Jan 2021 00:56:02 +0300 Subject: [PATCH 5/9] implement ISupportExternalScope --- .../Logging/SerilogLoggerProvider.cs | 37 +++++++++---------- .../Extensions/Logging/SerilogLoggerScope.cs | 33 ++--------------- .../Extensions/Logging/SerilogLoggerTests.cs | 2 +- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs index 9088b69..c58421b 100644 --- a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs +++ b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading; using Microsoft.Extensions.Logging; using Serilog.Core; using Serilog.Events; @@ -15,7 +14,7 @@ namespace Serilog.Extensions.Logging /// An that pipes events through Serilog. /// [ProviderAlias("Seq")] - class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher + class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher, ISupportExternalScope { internal const string OriginalFormatPropertyName = "{OriginalFormat}"; internal const string ScopePropertyName = "Scope"; @@ -23,6 +22,8 @@ class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher readonly Logger _logger; readonly Action _dispose; + IExternalScopeProvider _scopeProvider; + /// /// Construct a . /// @@ -44,44 +45,42 @@ public FrameworkLogger CreateLogger(string name) public IDisposable BeginScope(T state) { - return new SerilogLoggerScope(this, state); + return _scopeProvider.Push(state); } /// public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - List scopeItems = null; - for (var scope = CurrentScope; scope != null; scope = scope.Parent) + List scopeItems = new List(); + + _scopeProvider?.ForEachScope((scopeState, state) => { + var scope = new SerilogLoggerScope(scopeState); + LogEventPropertyValue scopeItem; - scope.EnrichAndCreateScopeItem(logEvent, propertyFactory, out scopeItem); + scope.EnrichAndCreateScopeItem(state.logEvent, state.propertyFactory, out scopeItem); if (scopeItem != null) { - scopeItems = scopeItems ?? new List(); - scopeItems.Add(scopeItem); + state.scopeItems.Add(scopeItem); } - } + }, (logEvent, propertyFactory, scopeItems)); - if (scopeItems != null) + if (scopeItems.Count > 0) { - scopeItems.Reverse(); logEvent.AddPropertyIfAbsent(new LogEventProperty(ScopePropertyName, new SequenceValue(scopeItems))); } } - readonly AsyncLocal _value = new AsyncLocal(); - - internal SerilogLoggerScope CurrentScope - { - get => _value.Value; - set => _value.Value = value; - } - /// public void Dispose() { _dispose(); } + + public void SetScopeProvider(IExternalScopeProvider scopeProvider) + { + _scopeProvider = scopeProvider; + } } } diff --git a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs index be36a18..5dcd317 100644 --- a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs +++ b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs @@ -1,48 +1,21 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using Serilog.Core; using Serilog.Events; namespace Serilog.Extensions.Logging { - class SerilogLoggerScope : IDisposable + readonly struct SerilogLoggerScope { const string NoName = "None"; - readonly SerilogLoggerProvider _provider; readonly object _state; - // An optimization only, no problem if there are data races on this. - bool _disposed; - - public SerilogLoggerScope(SerilogLoggerProvider provider, object state) + public SerilogLoggerScope(object state) { - _provider = provider; _state = state; - - Parent = _provider.CurrentScope; - _provider.CurrentScope = this; - } - - public SerilogLoggerScope Parent { get; } - - public void Dispose() - { - if (!_disposed) - { - _disposed = true; - - // In case one of the parent scopes has been disposed out-of-order, don't - // just blindly reinstate our own parent. - for (var scan = _provider.CurrentScope; scan != null; scan = scan.Parent) - { - if (ReferenceEquals(scan, this)) - _provider.CurrentScope = Parent; - } - } } public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory propertyFactory, out LogEventPropertyValue scopeItem) @@ -76,7 +49,7 @@ public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory } var property = propertyFactory.CreateProperty(key, stateProperty.Value, destructureObject); - logEvent.AddPropertyIfAbsent(property); + logEvent.AddOrUpdateProperty(property); } } else diff --git a/test/Seq.Extensions.Logging.Tests/Serilog/Extensions/Logging/SerilogLoggerTests.cs b/test/Seq.Extensions.Logging.Tests/Serilog/Extensions/Logging/SerilogLoggerTests.cs index 73d91ce..a9fd34a 100644 --- a/test/Seq.Extensions.Logging.Tests/Serilog/Extensions/Logging/SerilogLoggerTests.cs +++ b/test/Seq.Extensions.Logging.Tests/Serilog/Extensions/Logging/SerilogLoggerTests.cs @@ -12,7 +12,6 @@ using Serilog.Extensions.Logging; using Seq.Extensions.Logging; using Tests.Serilog.Extensions.Logging.Support; -using Serilog.Core.Enrichers; namespace Tests.Serilog.Extensions.Logging { @@ -28,6 +27,7 @@ private Tuple SetUp(LogLevel logLevel) var l = new global::Serilog.Core.Logger(new global::Serilog.Core.LoggingLevelSwitch(logLevel), sink); var provider = new SerilogLoggerProvider(l); + provider.SetScopeProvider(new LoggerExternalScopeProvider()); var logger = (SerilogLogger)provider.CreateLogger(Name); return new Tuple(logger, sink); From f75547516202ab78c4a79153770d77304e74efe0 Mon Sep 17 00:00:00 2001 From: Sergey Komisarchik Date: Wed, 6 Jan 2021 01:16:23 +0300 Subject: [PATCH 6/9] build warnings/errors fixes --- asset/icon.png | Bin 0 -> 6683 bytes .../ConsoleApplication/ConsoleApplication.csproj | 2 +- example/WebApplication/WebApplication.csproj | 6 ++---- .../Seq.Extensions.Logging.csproj | 6 +++++- .../Seq.Extensions.Logging.Tests.csproj | 6 +----- 5 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 asset/icon.png diff --git a/asset/icon.png b/asset/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ed37092a0647fa008fb640b51ac049a0e18f7472 GIT binary patch literal 6683 zcmd5>`9IX%+y6`xlf6>bFcqc6gxtC_wvzBrmfZH8lB^*#!k}cy5*6JTLM8iBvTsQw ziL9leC~L-~F+x1&b4K6i^?Lq-?+;!+=bY=h&UL-7_jR3fUK3?-R*Q#IgcCs!9v$sd zMhJpQK>xO|gBfyz;v4X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gdh3iU_(fU-cy#N}JdtK=-m08URjKs~kB8Mos; z>V%P*B}h~B((}(Y(>~Y@V>u5<{$54Pwd67g3#aq>ptD|2mkY@9fX(*moH<0ZmO88n z-`7h|U;-ya~{#tuGrp*vW1R#F*&E|)vnnZh7_{^lx z@O^hMc`I38dfAG^Nh8|vQE0O#m{F7&l1cpgWZei^5LyfDs}B1$OhnjQ*w}O2EBz6E z=(>A%q4om*VB zlUhn49l@-|p~1*Y@hNn1@*2_hlGC9;QfnPHWfN*kvTq)U{!5}EvlLXcObe|;CQl;; z3R)B%s#FX1FfapQfWl717wuUr*@)MYVihO^zuDd9JJUfao){qo&bj$03xOW`DRvd2ptA*538A%^`lg4cy^B!}xLXo%>Nm4_e-UQ

4EyzzsQ7ysoP= z8_lFxRNWc)AS9OH&X^m0ebJ-jIjIv-(g!M|WVeDVIG;XOwgfR?(Ggol@-mqZW+-8t zbiwj#G9bBFSDJ9Gb=_%XCWcj}VY%GEtchr5Ffk?9hiA0_)Ox{dMkh1?#z#r+W3DeIXKr#cs z__Zt^^bFHyLrqcBGdKf15UrF@!biY|uX{BHjYct_shB${-1fRBaN`e2QcF3@B+Q*~ zFz#m0q3%>ZE_>+j6G4T@YXHVW1FR8;hq>DRfc#}8%pK56bWfnb+1&zP7{UcI9KVAD?e*t6ti5;6#i zJCRQ22A#~OZvfLM07Bx%jh8N`jb3E@g_LMTlt?9Erg#N-D5AAGzn2m8=$M)(d(n_I z^lOw{kl)4o*05n8vI2HjQotW#cV^RiV#`P71G|d}CCuPdx78Z{wm?=vb-Rp_Z^e!f zTZ%D_5@07q9&J#DzgH3TyZ~>E-svwZ9i^@V~_JYx)z6$AD=kB0p=>EyA=59UT5>He4h ks__4Q0GT!4u_|%qCMi5^s9g^Hkb~%Go;_7`(k|?O0Xp`D!T Exe - netcoreapp3.0 + netcoreapp3.1 diff --git a/example/WebApplication/WebApplication.csproj b/example/WebApplication/WebApplication.csproj index 3996676..e9bb95e 100644 --- a/example/WebApplication/WebApplication.csproj +++ b/example/WebApplication/WebApplication.csproj @@ -1,12 +1,10 @@ - netcoreapp2.0 + netcoreapp2.1 true WebApplication Exe - WebApplication - 2.0.0 @@ -20,7 +18,7 @@ - + diff --git a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj index 72a5a36..cedaf7b 100644 --- a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj +++ b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj @@ -11,7 +11,7 @@ true true aspnet;logging - https://datalust.co/images/nuget/seq.png + icon.png https://github.com/datalust/seq-extensions-logging Apache-2.0 @@ -22,4 +22,8 @@ + + + + diff --git a/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj b/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj index 2643083..be64d24 100644 --- a/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj +++ b/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj @@ -1,7 +1,7 @@  - net472;netcoreapp3.0 + net472;netcoreapp3.1 ../../asset/seqext.snk true true @@ -20,8 +20,4 @@ - - - - From 48ee943d5d1a761811df996079e77451e7944538 Mon Sep 17 00:00:00 2001 From: Sergey Komisarchik Date: Wed, 6 Jan 2021 01:37:07 +0300 Subject: [PATCH 7/9] BeginScope() fix, net5.0 sample --- example/WebApplication/Startup.cs | 4 +++- example/WebApplication/WebApplication.csproj | 4 ++-- example/WebApplication/appsettings.json | 5 ++++- .../Serilog/Extensions/Logging/SerilogLoggerProvider.cs | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/example/WebApplication/Startup.cs b/example/WebApplication/Startup.cs index f80fcaa..e830d22 100644 --- a/example/WebApplication/Startup.cs +++ b/example/WebApplication/Startup.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -23,6 +24,8 @@ public Startup(IHostingEnvironment env) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.Configure(Configuration.GetSection("MvcOptions")); + services.AddLogging(loggingBuilder => { // Add the Seq logger, with configuration from appsettings.json @@ -42,7 +45,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseBrowserLink(); } else { diff --git a/example/WebApplication/WebApplication.csproj b/example/WebApplication/WebApplication.csproj index e9bb95e..d1bdf79 100644 --- a/example/WebApplication/WebApplication.csproj +++ b/example/WebApplication/WebApplication.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + net5.0;netcoreapp2.1 true WebApplication Exe @@ -17,7 +17,7 @@ - + diff --git a/example/WebApplication/appsettings.json b/example/WebApplication/appsettings.json index ba11e4d..937cf83 100644 --- a/example/WebApplication/appsettings.json +++ b/example/WebApplication/appsettings.json @@ -4,8 +4,11 @@ "Default": "Information" }, "Seq": { - "ServerUrl": "http://localhost:5341", + "ServerUrl": "http://localhost:9083", "ApiKey": "" } + }, + "MvcOptions": { + "EnableEndpointRouting": false } } diff --git a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs index c58421b..e4e946d 100644 --- a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs +++ b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs @@ -45,7 +45,7 @@ public FrameworkLogger CreateLogger(string name) public IDisposable BeginScope(T state) { - return _scopeProvider.Push(state); + return _scopeProvider?.Push(state); } /// From f9509a6a9b02d9922972b4bc78fd471577ea0591 Mon Sep 17 00:00:00 2001 From: Sergey Komisarchik Date: Wed, 6 Jan 2021 01:40:18 +0300 Subject: [PATCH 8/9] revert web sample seq url --- example/WebApplication/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/WebApplication/appsettings.json b/example/WebApplication/appsettings.json index 937cf83..60f7e58 100644 --- a/example/WebApplication/appsettings.json +++ b/example/WebApplication/appsettings.json @@ -4,7 +4,7 @@ "Default": "Information" }, "Seq": { - "ServerUrl": "http://localhost:9083", + "ServerUrl": "http://localhost:5341", "ApiKey": "" } }, From b10cdb766c3979999af279cd29366be1a5e536fd Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 6 Jan 2021 15:14:03 +1000 Subject: [PATCH 9/9] Minor clean-up, re-publish 5.0, add .NET 5.0 targets (#38) Update publishing key to reattempt 5.0 publishing; add net5.0 targets --- appveyor.yml | 2 +- .../ConsoleApplication.csproj | 2 +- example/WebApplication/Startup.cs | 5 ++-- example/WebApplication/WebApplication.csproj | 2 +- global.json | 6 +++++ seq-extensions-logging.sln | 3 +++ seq-extensions-logging.sln.DotSettings | 3 +++ .../Seq.Extensions.Logging.csproj | 5 ++-- .../Logging/ExceptionDataEnricher.cs | 12 +++------ .../Logging/SerilogLoggerProvider.cs | 9 +++---- .../Extensions/Logging/SerilogLoggerScope.cs | 26 +++++++------------ .../Seq.Extensions.Logging.Tests.csproj | 2 +- 12 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 global.json diff --git a/appveyor.yml b/appveyor.yml index 2f75401..80928a3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: 94298ksNMfJ2LkBV3Lw9o4JVzKvVPPMHF91p0XjsBhNWVeMX2NeROX4fpio6BsQy + secure: QYBIGd/prsJud8qlJati9FdnXbiA0VvyxO1z0TUiQV3svdpbD7ZaykJFTYKyIdQq skip_symbols: true on: branch: /^(main|dev)$/ diff --git a/example/ConsoleApplication/ConsoleApplication.csproj b/example/ConsoleApplication/ConsoleApplication.csproj index 58e30e2..b10ddf3 100644 --- a/example/ConsoleApplication/ConsoleApplication.csproj +++ b/example/ConsoleApplication/ConsoleApplication.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 diff --git a/example/WebApplication/Startup.cs b/example/WebApplication/Startup.cs index e830d22..7645c57 100644 --- a/example/WebApplication/Startup.cs +++ b/example/WebApplication/Startup.cs @@ -3,13 +3,14 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace WebApplication { public class Startup { - public Startup(IHostingEnvironment env) + public Startup(IWebHostEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) @@ -40,7 +41,7 @@ public void ConfigureServices(IServiceCollection services) } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { diff --git a/example/WebApplication/WebApplication.csproj b/example/WebApplication/WebApplication.csproj index d1bdf79..da94f0a 100644 --- a/example/WebApplication/WebApplication.csproj +++ b/example/WebApplication/WebApplication.csproj @@ -1,7 +1,7 @@ - net5.0;netcoreapp2.1 + net5.0 true WebApplication Exe diff --git a/global.json b/global.json new file mode 100644 index 0000000..52599fd --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "5.0.100", + "rollForward": "latestFeature" + } +} \ No newline at end of file diff --git a/seq-extensions-logging.sln b/seq-extensions-logging.sln index 1d425a7..2e68bf9 100644 --- a/seq-extensions-logging.sln +++ b/seq-extensions-logging.sln @@ -11,6 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{B0D573 Build.ps1 = Build.ps1 LICENSE = LICENSE README.md = README.md + global.json = global.json + .gitattributes = .gitattributes + .gitignore = .gitignore EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D54DE844-AC36-4872-928F-5F573D41ACAE}" diff --git a/seq-extensions-logging.sln.DotSettings b/seq-extensions-logging.sln.DotSettings index 4927542..1c67b9a 100644 --- a/seq-extensions-logging.sln.DotSettings +++ b/seq-extensions-logging.sln.DotSettings @@ -1,3 +1,6 @@  <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb" /></Policy> + True + True + True True \ No newline at end of file diff --git a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj index cedaf7b..7949ffe 100644 --- a/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj +++ b/src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj @@ -2,9 +2,9 @@ Add centralized structured log collection to ASP.NET Core apps with one line of code. - 5.0.1 + 5.0.0 Datalust and Contributors - net462;netstandard2.0 + net462;netstandard2.0;net5.0 true true ../../asset/seqext.snk @@ -14,6 +14,7 @@ icon.png https://github.com/datalust/seq-extensions-logging Apache-2.0 + diff --git a/src/Seq.Extensions.Logging/Seq/Extensions/Logging/ExceptionDataEnricher.cs b/src/Seq.Extensions.Logging/Seq/Extensions/Logging/ExceptionDataEnricher.cs index fe0f039..ef2fcd6 100644 --- a/src/Seq.Extensions.Logging/Seq/Extensions/Logging/ExceptionDataEnricher.cs +++ b/src/Seq.Extensions.Logging/Seq/Extensions/Logging/ExceptionDataEnricher.cs @@ -1,4 +1,4 @@ -// Copyright 2016 Datalust +// Copyright 2016-2020 Datalust and Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,15 +23,11 @@ class ExceptionDataEnricher : ILogEventEnricher { public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - if (logEvent.Exception == null) + var exceptionData = logEvent.Exception?.GetBaseException().Data; + if (exceptionData == null || exceptionData.Count == 0) return; - var exception = logEvent.Exception.GetBaseException(); - - if (exception.Data == null || exception.Data.Count == 0) - return; - - var data = exception.Data + var data = exceptionData .Cast() .Where(e => e.Key is string) .Select(e => propertyFactory.CreateProperty((string)e.Key, e.Value)); diff --git a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs index e4e946d..4ea3a5f 100644 --- a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs +++ b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerProvider.cs @@ -51,15 +51,12 @@ public IDisposable BeginScope(T state) /// public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - List scopeItems = new List(); + var scopeItems = new List(); _scopeProvider?.ForEachScope((scopeState, state) => { - var scope = new SerilogLoggerScope(scopeState); - - LogEventPropertyValue scopeItem; - scope.EnrichAndCreateScopeItem(state.logEvent, state.propertyFactory, out scopeItem); - + SerilogLoggerScope.EnrichAndCreateScopeItem(scopeState, state.logEvent, state.propertyFactory, out var scopeItem); + if (scopeItem != null) { state.scopeItems.Add(scopeItem); diff --git a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs index 5dcd317..62bbe66 100644 --- a/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs +++ b/src/Seq.Extensions.Logging/Serilog/Extensions/Logging/SerilogLoggerScope.cs @@ -1,5 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Modifications Copyright (c) Datalust and Contributors +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. using System.Collections.Generic; using Serilog.Core; @@ -7,27 +8,18 @@ namespace Serilog.Extensions.Logging { - readonly struct SerilogLoggerScope + static class SerilogLoggerScope { const string NoName = "None"; - - readonly object _state; - - public SerilogLoggerScope(object state) - { - _state = state; - } - - public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory propertyFactory, out LogEventPropertyValue scopeItem) + + public static void EnrichAndCreateScopeItem(object state, LogEvent logEvent, ILogEventPropertyFactory propertyFactory, out LogEventPropertyValue scopeItem) { - if (_state == null) + if (state == null) { scopeItem = null; - return; } - var stateProperties = _state as IEnumerable>; - if (stateProperties != null) + if (state is IEnumerable> stateProperties) { scopeItem = null; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items. @@ -35,7 +27,7 @@ public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory { if (stateProperty.Key == SerilogLoggerProvider.OriginalFormatPropertyName && stateProperty.Value is string) { - scopeItem = new ScalarValue(_state.ToString()); + scopeItem = new ScalarValue(state.ToString()); continue; } @@ -54,7 +46,7 @@ public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory } else { - scopeItem = propertyFactory.CreateProperty(NoName, _state).Value; + scopeItem = propertyFactory.CreateProperty(NoName, state).Value; } } } diff --git a/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj b/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj index be64d24..05ad0a3 100644 --- a/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj +++ b/test/Seq.Extensions.Logging.Tests/Seq.Extensions.Logging.Tests.csproj @@ -1,7 +1,7 @@  - net472;netcoreapp3.1 + net472;netcoreapp3.1;net5.0 ../../asset/seqext.snk true true