-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Scopes in Logger #471
Conversation
I would appreciate if someone help me run tests - they are failing for me on master |
// https://docs.asp.net/en/latest/fundamentals/logging.html#scopes | ||
return new NoOpDisposable(); | ||
} | ||
public IDisposable BeginScope<TState>(TState state) => ScopeProvider?.Push(state) ?? NullScope.Instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using NullScope from ASP.NET Core internal namespace we should continue to use the existing NoOpDisposable object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I'll bring back NoOpDisposable
Thanks for the PR. I'm taking a look and testing in practice. Looks like a good change. |
|
||
var components = new List<string>(4); | ||
if (_options.IncludeLogLevel) | ||
{ | ||
components.Add($"[{logLevel}]"); | ||
} | ||
|
||
GetScopeInformation(components, multiLine: _options.IncludeNewline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing scopes always being included regardless of what IncludeScopes
is set to. Seems like we need an if check before calling GetScopeInformation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I've missed it.
I based my implementation on https://github.com/aspnet/Extensions/blob/642b9263abe16ba1cd038f27c8cb4661763ff5bb/src/Logging/Logging.Console/src/ConsoleLogger.cs#L293 but missed that condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would not log scopes even without the check, since Scopes would be set to NullExternalScopeProvider
I think it's more readable with the check like you suggested
PR is merged into the dev branch. I'll update and close the PR once the feature has been merged to master and released. |
Version 2.3.0 has been released with this PR. Thanks again for the PR. |
Issue #, if available: outdated readme
Description of changes: Updated dependencies and added support for scopes
I think this is a super important feature for lambda logger.
Logs without scope are pretty much useless if lambda is getting traffic.
After this change you can do:
and all your logs will have
awsRequestId
in them. It makes it easy to find/filter and read logs in cloudwatch.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.