-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauricio Dominguez
committed
Jan 10, 2020
1 parent
3cbe13c
commit 3d8482b
Showing
4 changed files
with
139 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Serilog; | ||
using Serilog.Events; | ||
|
||
using Xunit.Sdk; | ||
|
||
namespace Honeycomb.Serilog.Sink.Tests.Helpers | ||
{ | ||
static class Some | ||
{ | ||
public static LogEvent LogEvent(string messageTemplate, params object[] propertyValues) | ||
{ | ||
return LogEvent(null, messageTemplate, propertyValues); | ||
} | ||
|
||
public static LogEvent LogEvent(Exception exception, string messageTemplate, params object[] propertyValues) | ||
{ | ||
return LogEvent(LogEventLevel.Information, exception, messageTemplate, propertyValues); | ||
} | ||
|
||
public static LogEvent LogEvent(LogEventLevel level, Exception exception, string messageTemplate, params object[] propertyValues) | ||
{ | ||
var log = new LoggerConfiguration().CreateLogger(); | ||
MessageTemplate template; | ||
IEnumerable<LogEventProperty> properties; | ||
#pragma warning disable Serilog004 // Constant MessageTemplate verifier | ||
if (!log.BindMessageTemplate(messageTemplate, propertyValues, out template, out properties)) | ||
#pragma warning restore Serilog004 // Constant MessageTemplate verifier | ||
{ | ||
throw new XunitException("Template could not be bound."); | ||
} | ||
return new LogEvent(DateTimeOffset.Now, level, exception, template, properties); | ||
} | ||
|
||
public static LogEvent LogEvent(LogEventLevel level, string messageTemplate, params object[] propertyValues) | ||
{ | ||
var log = new LoggerConfiguration().CreateLogger(); | ||
|
||
#pragma warning disable Serilog004 // Constant MessageTemplate verifier | ||
if (!log.BindMessageTemplate(messageTemplate, propertyValues, out var template, out var properties)) | ||
#pragma warning restore Serilog004 // Constant MessageTemplate verifier | ||
{ | ||
throw new XunitException("Template could not be bound."); | ||
} | ||
return new LogEvent(DateTimeOffset.Now, level, null, template, properties); | ||
} | ||
|
||
public static LogEvent DebugEvent() | ||
{ | ||
return LogEvent(LogEventLevel.Debug, null, "Debug event"); | ||
} | ||
|
||
public static LogEvent InformationEvent() | ||
{ | ||
return LogEvent(LogEventLevel.Information, null, "Information event"); | ||
} | ||
|
||
public static LogEvent ErrorEvent() | ||
{ | ||
return LogEvent(LogEventLevel.Error, null, "Error event"); | ||
} | ||
|
||
public static string String() | ||
{ | ||
return Guid.NewGuid().ToString("n"); | ||
} | ||
} | ||
} |
13 changes: 11 additions & 2 deletions
13
test/Honeycomb.Serilog.Sink.Tests/HoneycombSerilogSinkStub.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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
using Serilog.Events; | ||
|
||
namespace Honeycomb.Serilog.Sink.Tests | ||
{ | ||
internal class HoneycombSerilogSinkStub : HoneycombSerilogSink | ||
{ | ||
private readonly HttpClient _client; | ||
|
||
public HoneycombSerilogSinkStub(HttpClient client, string teamId, string apiKey) | ||
: base(teamId, apiKey, 1, TimeSpan.FromMilliseconds(1)) | ||
public HoneycombSerilogSinkStub(HttpClient client, string teamId, string apiKey, int batchSizeLimit, TimeSpan period) | ||
: base(teamId, apiKey, batchSizeLimit, period) | ||
{ | ||
_client = client; | ||
} | ||
|
||
protected override HttpClient Client => _client; | ||
|
||
public Task EmitTestable(params LogEvent[] events) | ||
{ | ||
return EmitBatchAsync(events); | ||
} | ||
} | ||
} |
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