forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoggerEnrichmentConfiguration.Wrap()
- Loading branch information
1 parent
a1e9850
commit ac5400b
Showing
9 changed files
with
133 additions
and
9 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
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
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
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,19 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Tests.Support | ||
{ | ||
class CollectingEnricher : ILogEventEnricher | ||
{ | ||
public List<LogEvent> Events { get; } = new List<LogEvent>(); | ||
|
||
public LogEvent SingleEvent => Events.Single(); | ||
|
||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
Events.Add(logEvent); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Tests.Support | ||
{ | ||
class ConditionalEnricher : ILogEventEnricher, IDisposable | ||
{ | ||
readonly ILogEventEnricher _wrapped; | ||
readonly Func<LogEvent, bool> _condition; | ||
|
||
public ConditionalEnricher(ILogEventEnricher wrapped, Func<LogEvent, bool> condition) | ||
{ | ||
_wrapped = wrapped; | ||
_condition = condition; | ||
} | ||
|
||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
if (_condition(logEvent)) | ||
_wrapped.Enrich(logEvent, propertyFactory); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
(_wrapped as IDisposable)?.Dispose(); | ||
} | ||
} | ||
} |
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