Skip to content

Commit b303dd5

Browse files
committed
Added support for pushing content of serilog Tags property via exceptionless client
1 parent bbb2737 commit b303dd5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Exceptionless;
45
using Exceptionless.Logging;
56
using Serilog.Core;
@@ -36,6 +37,24 @@ internal static string GetSource(this LogEvent log) {
3637
return null;
3738
}
3839

40+
internal static string[] GetTags(this LogEvent log)
41+
{
42+
if (log.Properties.TryGetValue("Tags", out LogEventPropertyValue value))
43+
{
44+
var propertyCollection = value.FlattenProperties() as List<object>;
45+
if (propertyCollection == null) return Array.Empty<string>();
46+
47+
List<string> tags = new List<string>();
48+
foreach (var item in propertyCollection)
49+
{
50+
tags.Add(item.ToString());
51+
}
52+
53+
return tags.ToArray();
54+
}
55+
return Array.Empty<string>();
56+
}
57+
3958
internal static LogLevel GetLevel(this LogEventLevel log)
4059
{
4160
switch (log)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void Emit(LogEvent logEvent) {
108108
if (logEvent.Level.GetLevel() < minLogLevel)
109109
return;
110110

111-
var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags);
111+
var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags).AddTags(logEvent.GetTags());
112112

113113
if (_includeProperties) {
114114
foreach (var prop in logEvent.Properties)

0 commit comments

Comments
 (0)