-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from datalust/dev
Release
- Loading branch information
Showing
10 changed files
with
154 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Serilog.Core; | ||
|
||
namespace SeqCli.Ingestion | ||
{ | ||
class EnrichingReader : ILogEventReader | ||
{ | ||
readonly ILogEventReader _inner; | ||
readonly IReadOnlyCollection<ILogEventEnricher> _enrichers; | ||
|
||
public EnrichingReader( | ||
ILogEventReader inner, | ||
IReadOnlyCollection<ILogEventEnricher> enrichers) | ||
{ | ||
_inner = inner ?? throw new ArgumentNullException(nameof(inner)); | ||
_enrichers = enrichers ?? throw new ArgumentNullException(nameof(enrichers)); | ||
} | ||
|
||
public async Task<ReadResult> TryReadAsync() | ||
{ | ||
var result = await _inner.TryReadAsync(); | ||
|
||
if (result.LogEvent != null) | ||
{ | ||
foreach (var enricher in _enrichers) | ||
enricher.Enrich(result.LogEvent, null); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System.Threading.Tasks; | ||
using Serilog.Events; | ||
|
||
namespace SeqCli.Ingestion | ||
{ | ||
|
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,37 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
|
||
namespace SeqCli.Ingestion | ||
{ | ||
class StaticMessageTemplateReader : ILogEventReader | ||
{ | ||
readonly ILogEventReader _inner; | ||
readonly MessageTemplate _messageTemplate; | ||
|
||
public StaticMessageTemplateReader(ILogEventReader inner, string messageTemplate) | ||
{ | ||
_inner = inner ?? throw new ArgumentNullException(nameof(inner)); | ||
_messageTemplate = new MessageTemplateParser().Parse(messageTemplate); | ||
} | ||
|
||
public async Task<ReadResult> TryReadAsync() | ||
{ | ||
var result = await _inner.TryReadAsync(); | ||
|
||
if (result.LogEvent == null) | ||
return result; | ||
|
||
var evt = new LogEvent( | ||
result.LogEvent.Timestamp, | ||
result.LogEvent.Level, | ||
result.LogEvent.Exception, | ||
_messageTemplate, | ||
result.LogEvent.Properties.Select(kv => new LogEventProperty(kv.Key, kv.Value))); | ||
|
||
return new ReadResult(evt, result.IsAtEnd); | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
test/SeqCli.Tests/PlainText/StaticMessageTemplateReaderTests.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,21 @@ | ||
using System.Threading.Tasks; | ||
using SeqCli.Ingestion; | ||
using SeqCli.Tests.Support; | ||
using Xunit; | ||
|
||
namespace SeqCli.Tests.PlainText | ||
{ | ||
public class StaticMessageTemplateReaderTests | ||
{ | ||
[Fact] | ||
public async Task ReaderSubstitutesMessageTemplate() | ||
{ | ||
var evt = Some.LogEvent(); | ||
const string mt = "This is a message template"; | ||
var reader = new FixedLogEventReader(new ReadResult(evt, false)); | ||
var wrapper = new StaticMessageTemplateReader(reader, mt); | ||
var result = await wrapper.TryReadAsync(); | ||
Assert.Equal(mt, result.LogEvent.MessageTemplate.Text); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System.Threading.Tasks; | ||
using SeqCli.Ingestion; | ||
|
||
namespace SeqCli.Tests.Support | ||
{ | ||
class FixedLogEventReader : ILogEventReader | ||
{ | ||
readonly ReadResult _result; | ||
|
||
public FixedLogEventReader(ReadResult result) | ||
{ | ||
_result = result; | ||
} | ||
|
||
public Task<ReadResult> TryReadAsync() | ||
{ | ||
return Task.FromResult(_result); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Linq; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
|
||
namespace SeqCli.Tests.Support | ||
{ | ||
static class Some | ||
{ | ||
public static LogEvent LogEvent() | ||
{ | ||
return new LogEvent( | ||
DateTimeOffset.UtcNow, | ||
LogEventLevel.Information, | ||
null, | ||
new MessageTemplateParser().Parse("Test"), | ||
Enumerable.Empty<LogEventProperty>()); | ||
} | ||
} | ||
} |