From b303dd543522b0be651588067ddcec7770d13a22 Mon Sep 17 00:00:00 2001 From: David Noakes Date: Tue, 23 Jul 2024 14:29:04 +0200 Subject: [PATCH] Added support for pushing content of serilog Tags property via exceptionless client --- .../ExceptionlessClientExtensions.cs | 19 +++++++++++++++++++ .../Sinks/Exceptionless/ExceptionlessSink.cs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs index 5e7d735..1c3095a 100644 --- a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs +++ b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Exceptionless; using Exceptionless.Logging; using Serilog.Core; @@ -36,6 +37,24 @@ internal static string GetSource(this LogEvent log) { return null; } + internal static string[] GetTags(this LogEvent log) + { + if (log.Properties.TryGetValue("Tags", out LogEventPropertyValue value)) + { + var propertyCollection = value.FlattenProperties() as List; + if (propertyCollection == null) return Array.Empty(); + + List tags = new List(); + foreach (var item in propertyCollection) + { + tags.Add(item.ToString()); + } + + return tags.ToArray(); + } + return Array.Empty(); + } + internal static LogLevel GetLevel(this LogEventLevel log) { switch (log) diff --git a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs index f4b043a..a9afc41 100644 --- a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs +++ b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs @@ -108,7 +108,7 @@ public void Emit(LogEvent logEvent) { if (logEvent.Level.GetLevel() < minLogLevel) return; - var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags); + var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags).AddTags(logEvent.GetTags()); if (_includeProperties) { foreach (var prop in logEvent.Properties)