diff --git a/README.md b/README.md index 7c98b60..2e27082 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,19 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` +To get tags to populate on the exceptionless UI, add a `Tags` string enumerable to any log. + +```Example with Serilog: +Serilog: Log.ForContext("Tags", new List() { "Tag1", "Tag2"}).Information("Seri info"); +``` + +```Example with ILogger +using (var scope = _logger.BeginScope(new Dictionary { ["Tags"] = new string[] { "Tag1", "Tag2" }})) +{ +_logger.Log(logLevel, eventId, state, exception, formatter); +} +``` + * [Documentation](https://github.com/serilog/serilog/wiki) Copyright © 2023 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). diff --git a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs index 5e7d735..141ba2a 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,20 @@ internal static string GetSource(this LogEvent log) { return null; } + internal static string[] GetTags(this 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(); + } + 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..21dc1c0 100644 --- a/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs +++ b/src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs @@ -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;