-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RegexMatchTimeoutExceptionDestructurer for RegexMatchTimeoutExcep…
…tion
- Loading branch information
1 parent
c9f1374
commit 578cb79
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Source/Serilog.Exceptions/Destructurers/RegexMatchTimeoutExceptionDestructurer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Serilog.Exceptions.Destructurers | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using Serilog.Exceptions.Core; | ||
|
||
/// <summary> | ||
/// Destructurer for <see cref="RegexMatchTimeoutException"/>. | ||
/// </summary> | ||
public class RegexMatchTimeoutExceptionDestructurer | ||
: ExceptionDestructurer | ||
{ | ||
/// <inheritdoc cref="IExceptionDestructurer.TargetTypes"/> | ||
public override Type[] TargetTypes => new Type[] | ||
{ | ||
typeof(RegexMatchTimeoutException), | ||
}; | ||
|
||
/// <inheritdoc cref="IExceptionDestructurer.Destructure"/> | ||
public override void Destructure(Exception exception, IExceptionPropertiesBag propertiesBag, Func<Exception, IReadOnlyDictionary<string, object?>?> destructureException) | ||
{ | ||
base.Destructure(exception, propertiesBag, destructureException); | ||
|
||
#pragma warning disable CA1062 // Validate arguments of public methods | ||
var typedException = (RegexMatchTimeoutException)exception; | ||
propertiesBag.AddProperty(nameof(RegexMatchTimeoutException.Input), typedException.Input); | ||
propertiesBag.AddProperty(nameof(RegexMatchTimeoutException.Pattern), typedException.Pattern); | ||
propertiesBag.AddProperty(nameof(RegexMatchTimeoutException.MatchTimeout), typedException.MatchTimeout.ToString("c")); | ||
#pragma warning restore CA1062 // Validate arguments of public methods | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Tests/Serilog.Exceptions.Test/Destructurers/RegexMatchTimeoutExceptionDestructurerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Serilog.Exceptions.Test.Destructurers | ||
{ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using Serilog.Exceptions.Core; | ||
using Serilog.Exceptions.Destructurers; | ||
using Xunit; | ||
using static LogJsonOutputUtils; | ||
|
||
public class RegexMatchTimeoutExceptionDestructurerTests | ||
{ | ||
[Fact] | ||
public void RegexMatchTimeoutException_ParamsAttachedAsProperties() | ||
{ | ||
var exception = new RegexMatchTimeoutException("input", "pattern", TimeSpan.FromSeconds(1)); | ||
|
||
var optionsBuilder = new DestructuringOptionsBuilder() | ||
.WithDestructurers(new IExceptionDestructurer[] | ||
{ | ||
new RegexMatchTimeoutExceptionDestructurer(), | ||
}); | ||
|
||
var loggedExceptionDetails = ExtractExceptionDetails(LogAndDestructureException(exception, optionsBuilder)); | ||
|
||
Assert_ContainsPropertyWithValue(loggedExceptionDetails, nameof(RegexMatchTimeoutException.Input), exception.Input); | ||
Assert_ContainsPropertyWithValue(loggedExceptionDetails, nameof(RegexMatchTimeoutException.Pattern), exception.Pattern); | ||
Assert_ContainsPropertyWithValue(loggedExceptionDetails, nameof(RegexMatchTimeoutException.MatchTimeout), exception.MatchTimeout.ToString("c")); | ||
} | ||
} | ||
} |