From d81a7dddb4f27c49b16510a26f47a122fe17e0e4 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 22 Jun 2022 17:14:57 -0400 Subject: [PATCH 1/2] netstandard2.0 --- .../Serilog.Exceptions.EntityFrameworkCore.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Serilog.Exceptions.EntityFrameworkCore/Serilog.Exceptions.EntityFrameworkCore.csproj b/Source/Serilog.Exceptions.EntityFrameworkCore/Serilog.Exceptions.EntityFrameworkCore.csproj index a96bc660..975245c9 100644 --- a/Source/Serilog.Exceptions.EntityFrameworkCore/Serilog.Exceptions.EntityFrameworkCore.csproj +++ b/Source/Serilog.Exceptions.EntityFrameworkCore/Serilog.Exceptions.EntityFrameworkCore.csproj @@ -1,7 +1,7 @@ - net6.0;net5.0;netstandard2.1 + net6.0;net5.0;netstandard2.1;netstandard2.0 @@ -22,4 +22,8 @@ + + + + From 937eaf8f410aea4b64f53ba26d04b2193c030658 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 11 Jan 2023 22:14:28 -0500 Subject: [PATCH 2/2] EntryCountLimit concept for DbUpdateExceptionDestructurer --- .../DbUpdateExceptionDestructurer.cs | 85 ++++++++++++------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/Source/Serilog.Exceptions.EntityFrameworkCore/Destructurers/DbUpdateExceptionDestructurer.cs b/Source/Serilog.Exceptions.EntityFrameworkCore/Destructurers/DbUpdateExceptionDestructurer.cs index 3e3391ea..b6cfeb56 100644 --- a/Source/Serilog.Exceptions.EntityFrameworkCore/Destructurers/DbUpdateExceptionDestructurer.cs +++ b/Source/Serilog.Exceptions.EntityFrameworkCore/Destructurers/DbUpdateExceptionDestructurer.cs @@ -13,34 +13,61 @@ namespace Serilog.Exceptions.EntityFrameworkCore.Destructurers; /// public class DbUpdateExceptionDestructurer : ExceptionDestructurer { - /// - public override Type[] TargetTypes => new[] { typeof(DbUpdateException), typeof(DbUpdateConcurrencyException) }; - - /// - public override void Destructure( - Exception exception, - IExceptionPropertiesBag propertiesBag, - Func?> destructureException) - { - base.Destructure(exception, propertiesBag, destructureException); - - var dbUpdateException = (DbUpdateException)exception; - var entriesValue = dbUpdateException.Entries? - .Select( - e => new + private readonly int? _entryCountLimit; + + /// + /// Initializes a new instance of the class. + /// + /// Limit of how many entries will be emitted. Null for unlimited. + public DbUpdateExceptionDestructurer(int? entryCountLimit = null) + { + _entryCountLimit = entryCountLimit; + } + + /// + public override Type[] TargetTypes => new[] + { + typeof(DbUpdateException), + typeof(DbUpdateConcurrencyException) + }; + + /// + public override void Destructure( + Exception exception, + IExceptionPropertiesBag propertiesBag, + Func?> destructureException + ) + { + base.Destructure(exception, propertiesBag, destructureException); + + var dbUpdateException = (DbUpdateException)exception; + + if (dbUpdateException.Entries != null) + { + propertiesBag.AddProperty("EntryCount", dbUpdateException.Entries.Count); + + var entriesQuery = dbUpdateException.Entries + .Select( + e => new + { + EntryProperties = e.Properties.Select( + p => new + { + PropertyName = p.Metadata.Name, + p.OriginalValue, + p.CurrentValue, + p.IsTemporary, + p.IsModified, + }), + e.State, + }); + + if (_entryCountLimit != null) { - EntryProperties = e.Properties.Select( - p => new - { - PropertyName = p.Metadata.Name, - p.OriginalValue, - p.CurrentValue, - p.IsTemporary, - p.IsModified, - }), - e.State, - }) - .ToList(); - propertiesBag.AddProperty(nameof(DbUpdateException.Entries), entriesValue); - } + entriesQuery = entriesQuery.Take(_entryCountLimit.Value); + } + + propertiesBag.AddProperty(nameof(DbUpdateException.Entries), entriesQuery.ToList()); + } + } }