Skip to content

Commit

Permalink
Moved getTags extension to LogEventPropertyValue and moved to the exi…
Browse files Browse the repository at this point in the history
…sting iteration through properties
  • Loading branch information
dnoakes committed Jul 24, 2024
1 parent b303dd5 commit c68cc0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>;
if (propertyCollection == null) return Array.Empty<string>();

List<string> tags = new List<string>();
foreach (var item in propertyCollection)
{
tags.Add(item.ToString());
}
var propertyCollection = value.FlattenProperties() as List<object>;
if (propertyCollection == null) return Array.Empty<string>();

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

return tags.ToArray();
}

internal static LogLevel GetLevel(this LogEventLevel 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).AddTags(logEvent.GetTags());
var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags);

if (_includeProperties) {
foreach (var prop in logEvent.Properties)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c68cc0c

Please sign in to comment.