Skip to content

Commit d71d3f8

Browse files
authored
Added tag support for including tags #18
2 parents bbb2737 + e0994dc commit d71d3f8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Diff for: README.md

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ Log.Logger = new LoggerConfiguration()
3636
.CreateLogger();
3737
```
3838

39+
To get tags to populate on the exceptionless UI, add a `Tags` string enumerable to any log.
40+
41+
```Example with Serilog:
42+
Serilog: Log.ForContext("Tags", new List() { "Tag1", "Tag2"}).Information("Seri info");
43+
```
44+
45+
```Example with ILogger
46+
using (var scope = _logger.BeginScope(new Dictionary<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" }}))
47+
{
48+
_logger.Log(logLevel, eventId, state, exception, formatter);
49+
}
50+
```
51+
3952
* [Documentation](https://github.com/serilog/serilog/wiki)
4053

4154
Copyright &copy; 2023 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).

Diff for: src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Exceptionless;
45
using Exceptionless.Logging;
56
using Serilog.Core;
@@ -36,6 +37,20 @@ internal static string GetSource(this LogEvent log) {
3637
return null;
3738
}
3839

40+
internal static string[] GetTags(this LogEventPropertyValue value)
41+
{
42+
var propertyCollection = value.FlattenProperties() as List<object>;
43+
if (propertyCollection == null) return Array.Empty<string>();
44+
45+
List<string> tags = new List<string>();
46+
foreach (var item in propertyCollection)
47+
{
48+
tags.Add(item.ToString());
49+
}
50+
51+
return tags.ToArray();
52+
}
53+
3954
internal static LogLevel GetLevel(this LogEventLevel log)
4055
{
4156
switch (log)

Diff for: src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public void Emit(LogEvent logEvent) {
139139
if (!String.IsNullOrWhiteSpace(emailAddress) || !String.IsNullOrWhiteSpace(description))
140140
builder.SetUserDescription(emailAddress, description);
141141
break;
142+
case "Tags":
143+
builder.AddTags(prop.Value.GetTags());
144+
break;
142145
default:
143146
builder.SetProperty(prop.Key, prop.Value.FlattenProperties());
144147
break;

0 commit comments

Comments
 (0)