Skip to content

Commit 1292296

Browse files
authored
Support adding default tags as discrete values in LoggerConfiguration… (#12)
1 parent 20a06d2 commit 1292296

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Serilog.Sinks.Exceptionless/LoggerSinkConfigurationExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ public static LoggerConfiguration Exceptionless(
3232
if (apiKey == null)
3333
throw new ArgumentNullException(nameof(apiKey));
3434

35-
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, null, additionalOperation, includeProperties), restrictedToMinimumLevel);
35+
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, null, null, additionalOperation, includeProperties), restrictedToMinimumLevel);
3636
}
37-
37+
3838
/// <summary>Creates a new Exceptionless sink with the specified <paramref name="apiKey"/>.</summary>
3939
/// <param name="loggerConfiguration">The logger configuration.</param>
4040
/// <param name="apiKey">The API key that will be used when sending events to the server.</param>
4141
/// <param name="serverUrl">Optional URL of the server events will be sent to.</param>
42+
/// <param name="defaultTags">Default tags to be added to every log event.</param>
4243
/// <param name="additionalOperation">Any additional operation to run against the build exceptions</param>
4344
/// <param name="includeProperties">If false it suppressed sending the Serilog properties to Exceptionless</param>
4445
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
@@ -48,6 +49,7 @@ public static LoggerConfiguration Exceptionless(
4849
this LoggerSinkConfiguration loggerConfiguration,
4950
string apiKey,
5051
string serverUrl = null,
52+
string[] defaultTags = null,
5153
Func<EventBuilder, EventBuilder> additionalOperation = null,
5254
bool includeProperties = true,
5355
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
@@ -58,7 +60,7 @@ public static LoggerConfiguration Exceptionless(
5860
if (apiKey == null)
5961
throw new ArgumentNullException(nameof(apiKey));
6062

61-
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, serverUrl, additionalOperation, includeProperties), restrictedToMinimumLevel);
63+
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, serverUrl, defaultTags, additionalOperation, includeProperties), restrictedToMinimumLevel);
6264
}
6365

6466
/// <summary>Creates a new Exceptionless sink.</summary>

src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Serilog.Sinks.Exceptionless {
1313
/// Exceptionless Sink
1414
/// </summary>
1515
public class ExceptionlessSink : ILogEventSink, IDisposable {
16+
private readonly string[] _defaultTags;
1617
private readonly Func<EventBuilder, EventBuilder> _additionalOperation;
1718
private readonly bool _includeProperties;
1819

@@ -27,6 +28,9 @@ public class ExceptionlessSink : ILogEventSink, IDisposable {
2728
/// <param name="serverUrl">
2829
/// Optional URL of the server events will be sent to.
2930
/// </param>
31+
/// <param name="defaultTags">
32+
/// Default tags to be added to every log event.
33+
/// </param>
3034
/// <param name="additionalOperation">
3135
/// Optional operation to run against the Error Builder before submitting to Exceptionless
3236
/// </param>
@@ -36,6 +40,7 @@ public class ExceptionlessSink : ILogEventSink, IDisposable {
3640
public ExceptionlessSink(
3741
string apiKey,
3842
string serverUrl = null,
43+
string[] defaultTags = null,
3944
Func<EventBuilder, EventBuilder> additionalOperation = null,
4045
bool includeProperties = true
4146
) {
@@ -53,6 +58,7 @@ public ExceptionlessSink(
5358
config.UseLogger(new SelfLogLogger());
5459
});
5560

61+
_defaultTags = defaultTags;
5662
_additionalOperation = additionalOperation;
5763
_includeProperties = includeProperties;
5864
}
@@ -89,6 +95,8 @@ public void Emit(LogEvent logEvent) {
8995

9096
var builder = _client.CreateFromLogEvent(logEvent);
9197

98+
builder.AddTags(_defaultTags);
99+
92100
if (_includeProperties && logEvent.Properties != null) {
93101
foreach (var prop in logEvent.Properties)
94102
{

0 commit comments

Comments
 (0)