question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for LoggerExtensions.BeginScope method

See original GitHub issue

Would love to see support for the LoggerExtensions.BeginScope method in Microsoft.Extensions.Logging: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loggerextensions.beginscope

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
olshcommented, Jun 2, 2021

Hi @iam-black

My bad, I forgot to add .Enrich.FromLogContext() in the logger configuration. Yes, your code should definitely work.

This is probably worth implementing, but this won’t be easy because you should investigate the entire call stack to determine the context. I’ll gladly accept PR.

Also, I’d like to mention that the main usage of the scope is to avoid repetition and add context to messages. We are using Elastic for logging too, and we attach the context properties to log messages without rendering them in the templates. In other words, we don’t put properties from scope to templates because they are attached anyway, and you can use them in Kibana filters.

1reaction
olshcommented, May 20, 2021

Interesting, I’ll take a look when I have spare time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LoggerExtensions.BeginScope(ILogger, String, Object[]) ...
Formats the message and creates a scope.
Read more >
Creating an extension method for attaching key-value pairs ...
In this post I describe a small extension method that makes logging scopes as key-value pairs in ASP.NET Core with Serilog and Seq...
Read more >
The semantics of ILogger.BeginScope()
The BeginScope() extension method used here creates an instance of the internal FormattedLogValues class, which is IEnumerable<KeyValuePair< ...
Read more >
Microsoft.Extensions.Logging custom implementation, how ...
Extension method for logging dotnet core webapi how do I get the calling projects/assembly name? 2 · Add method to existing Microsoft.Extensions ...
Read more >
Logging with ILogger in .NET: Recommendations and best ...
This article describes recommendations and best practices for using the ILogger based logging system which has been introduced with .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found