Skip to content

Commit 4afe5d6

Browse files
committed
Updated readme and added tags sample to demo app
1 parent 39d0472 commit 4afe5d6

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,9 @@ Log.Logger = new LoggerConfiguration()
3838

3939
To get tags to populate on the exceptionless UI, add a `Tags` string enumerable to any log.
4040

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-
{
41+
```csharp
42+
using var _ = _logger.BeginScope(new Dictionary<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" }});
4843
_logger.Log(logLevel, eventId, state, exception, formatter);
49-
}
5044
```
5145

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

sample/SampleWeb/Controllers/ValuesController.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using Exceptionless.Models;
45
using Exceptionless.Models.Data;
@@ -22,16 +23,18 @@ public ValuesController(ILogger<ValuesController> logger)
2223
[HttpGet]
2324
public string Get()
2425
{
26+
using var _ = _logger.BeginScope(new Dictionary<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" } });
2527
_logger.LogInformation("Get was called");
28+
2629
return $"[{Activity.Current?.Id}] {User.Identity?.Name}";
2730
}
2831

2932
[HttpGet("advanced-topic-user")]
3033
public string AdvancedTopicUser()
3134
{
32-
// This call is is authenticated so a user identity would automatically be set.
33-
// However we are overriding it with our own custom user. You may want to do this
34-
// in a microservice where you know the user but you may not be authenticated.
35+
// This call is authenticated so a user identity would automatically be set.
36+
// However, we are overriding it with our own custom user. You may want to do this
37+
// in a microservice where you know the user, but you may not be authenticated.
3538
using (LogContext.PushProperty(Event.KnownDataKeys.UserInfo, new UserInfo(User.Identity?.Name + " Custom", "Test User Full Name"), true))
3639
{
3740
_logger.LogInformation("This log event will have a custom user set.");

src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs

+3-8
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ internal static string GetSource(this LogEvent log)
4444
internal static string[] GetTags(this LogEventPropertyValue value)
4545
{
4646
var propertyCollection = value.FlattenProperties() as List<object>;
47-
if (propertyCollection == null) return Array.Empty<string>();
47+
if (propertyCollection == null)
48+
return Array.Empty<string>();
4849

49-
List<string> tags = new List<string>();
50-
foreach (var item in propertyCollection)
51-
{
52-
tags.Add(item.ToString());
53-
}
54-
55-
return tags.ToArray();
50+
return propertyCollection.Select(p => p.ToString()).ToArray();
5651
}
5752

5853
internal static LogLevel GetLevel(this LogEventLevel log)

0 commit comments

Comments
 (0)