From c68cc0c3bdbb4b8d40ed3a6e4fd4f40e66ae43bb Mon Sep 17 00:00:00 2001 From: David Noakes Date: Wed, 24 Jul 2024 08:20:24 +0200 Subject: [PATCH] Moved getTags extension to LogEventPropertyValue and moved to the existing iteration through properties --- .../ExceptionlessClientExtensions.cs | 22 ++++++++----------- .../Sinks/Exceptionless/ExceptionlessSink.cs | 5 ++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs index 1c3095a..141ba2a 100644 --- a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs +++ b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs @@ -37,22 +37,18 @@ internal static string GetSource(this LogEvent log) { return null; } - internal static string[] GetTags(this LogEvent log) + internal static string[] GetTags(this LogEventPropertyValue value) { - 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()); - } + var propertyCollection = value.FlattenProperties() as List; + if (propertyCollection == null) return Array.Empty(); - return tags.ToArray(); + List tags = new List(); + foreach (var item in propertyCollection) + { + tags.Add(item.ToString()); } - return Array.Empty(); + + return tags.ToArray(); } internal static LogLevel GetLevel(this LogEventLevel log) diff --git a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs index a9afc41..21dc1c0 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).AddTags(logEvent.GetTags()); + var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags); if (_includeProperties) { foreach (var prop in logEvent.Properties) @@ -139,6 +139,9 @@ public void Emit(LogEvent logEvent) { if (!String.IsNullOrWhiteSpace(emailAddress) || !String.IsNullOrWhiteSpace(description)) builder.SetUserDescription(emailAddress, description); break; + case "Tags": + builder.AddTags(prop.Value.GetTags()); + break; default: builder.SetProperty(prop.Key, prop.Value.FlattenProperties()); break;