-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/115 mask sensitive values (#175)
* Added LoggingConfig.SensitiveValues * Updated DefaultFormatter to mask sensitive values * Added LoggingConfig.ScopeFormatter * Added DefaultScopeFormatter * Updated ScopeWriter to use Config.ScopeFormatter * Renamed name parameters to categoryName * Updated documentation
- Loading branch information
1 parent
59372ab
commit 4c4bbe4
Showing
15 changed files
with
546 additions
and
139 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
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
61 changes: 61 additions & 0 deletions
61
Divergic.Logging.Xunit.UnitTests/DefaultScopeFormatterTests.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,61 @@ | ||
namespace Divergic.Logging.Xunit.UnitTests | ||
{ | ||
using System; | ||
using FluentAssertions; | ||
using global::Xunit; | ||
using global::Xunit.Abstractions; | ||
using Microsoft.Extensions.Logging; | ||
using ModelBuilder; | ||
|
||
public class DefaultScopeFormatterTests | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public DefaultScopeFormatterTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public void FormatReturnsRawValue() | ||
{ | ||
var config = new LoggingConfig(); | ||
var scopeLevel = 1; | ||
var categoryName = Guid.NewGuid().ToString(); | ||
var logLevel = LogLevel.Information; | ||
var eventId = Model.Create<EventId>(); | ||
var message = Guid.NewGuid().ToString(); | ||
|
||
var sut = new DefaultScopeFormatter(config); | ||
|
||
var actual = sut.Format(scopeLevel, categoryName, logLevel, eventId, message, null); | ||
|
||
_output.WriteLine(actual); | ||
|
||
actual.Should().Be($" {message}"); | ||
} | ||
|
||
[Fact] | ||
public void FormatReturnsValueWithException() | ||
{ | ||
var config = new LoggingConfig(); | ||
var scopeLevel = 1; | ||
var categoryName = Guid.NewGuid().ToString(); | ||
var logLevel = LogLevel.Information; | ||
var eventId = Model.Create<EventId>(); | ||
var message = Guid.NewGuid().ToString(); | ||
var exception = new ArgumentNullException(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); | ||
|
||
var sut = new DefaultScopeFormatter(config); | ||
|
||
var actual = sut.Format(scopeLevel, categoryName, logLevel, eventId, message, exception); | ||
|
||
_output.WriteLine(actual); | ||
|
||
actual.Should().Contain(message); | ||
actual.Should().Contain(exception.ToString()); | ||
actual.Should().NotContain(logLevel.ToString()); | ||
actual.Should().NotContain(eventId.Id.ToString()); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.