Skip to content

Commit

Permalink
Updated readme and added tags sample to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Jul 26, 2024
1 parent 39d0472 commit 4afe5d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ Log.Logger = new LoggerConfiguration()

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" }}))
{
```csharp
using var _ = _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)
Expand Down
9 changes: 6 additions & 3 deletions sample/SampleWeb/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Exceptionless.Models;
using Exceptionless.Models.Data;
Expand All @@ -22,16 +23,18 @@ public ValuesController(ILogger<ValuesController> logger)
[HttpGet]
public string Get()
{
using var _ = _logger.BeginScope(new Dictionary<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" } });
_logger.LogInformation("Get was called");

return $"[{Activity.Current?.Id}] {User.Identity?.Name}";
}

[HttpGet("advanced-topic-user")]
public string AdvancedTopicUser()
{
// This call is is authenticated so a user identity would automatically be set.
// However we are overriding it with our own custom user. You may want to do this
// in a microservice where you know the user but you may not be authenticated.
// This call is authenticated so a user identity would automatically be set.
// However, we are overriding it with our own custom user. You may want to do this
// in a microservice where you know the user, but you may not be authenticated.
using (LogContext.PushProperty(Event.KnownDataKeys.UserInfo, new UserInfo(User.Identity?.Name + " Custom", "Test User Full Name"), true))
{
_logger.LogInformation("This log event will have a custom user set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ internal static string GetSource(this LogEvent log)
internal static string[] GetTags(this LogEventPropertyValue value)
{
var propertyCollection = value.FlattenProperties() as List<object>;
if (propertyCollection == null) return Array.Empty<string>();
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 propertyCollection.Select(p => p.ToString()).ToArray();
}

internal static LogLevel GetLevel(this LogEventLevel log)
Expand Down

0 comments on commit 4afe5d6

Please sign in to comment.