Skip to content

Commit

Permalink
Added support for pushing content of serilog Tags property via except…
Browse files Browse the repository at this point in the history
…ionless client
  • Loading branch information
dnoakes committed Jul 23, 2024
1 parent bbb2737 commit b303dd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exceptionless;
using Exceptionless.Logging;
using Serilog.Core;
Expand Down Expand Up @@ -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<object>;
if (propertyCollection == null) return Array.Empty<string>();

List<string> tags = new List<string>();
foreach (var item in propertyCollection)
{
tags.Add(item.ToString());
}

return tags.ToArray();
}
return Array.Empty<string>();
}

internal static LogLevel GetLevel(this LogEventLevel log)
{
switch (log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b303dd5

Please sign in to comment.