Skip to content

Commit

Permalink
Added tag support for including tags #18
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski authored Jul 24, 2024
2 parents bbb2737 + e0994dc commit d71d3f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" }}))
{
_logger.Log(logLevel, eventId, state, exception, formatter);
}
```

* [Documentation](https://github.com/serilog/serilog/wiki)

Copyright &copy; 2023 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).
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,20 @@ internal static string GetSource(this LogEvent log) {
return null;
}

internal static string[] GetTags(this 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();
}

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

Please sign in to comment.