Skip to content
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

Detect IEnumerable<KeyValuePair<string, object>> in log scopes #215

Merged
merged 4 commits into from
Mar 26, 2021

Conversation

gkinsman
Copy link
Contributor

@gkinsman gkinsman commented Mar 25, 2021

This PR implements a potential solution from issue #214.

Instead of rendering => System.Collections.Generic.KeyValuePair2[System.String,System.Object][] for scope objects of this type, it renders this:

[2018-08-19 16:12:16Z] info: MyName[0]
      => ScopeKeyOne: ScopeValueOne
      => ScopeKeyTwo: ScopeValueTwo
      => ScopeKeyThree: ScopeValueThree
        => ScopeKeyFour: ScopeValueFour
        => ScopeKeyFive: ScopeValueFive
        => ScopeKeySix: ScopeValueSix
      Message|False|False

given this log message:

using (logger.BeginScope(new[]
{
    new KeyValuePair<string, object>("ScopeKeyOne", "ScopeValueOne"),
    new KeyValuePair<string, object>("ScopeKeyTwo", "ScopeValueTwo"),
    new KeyValuePair<string, object>("ScopeKeyThree", "ScopeValueThree"),
}))
{
    using (logger.BeginScope(new[]
    {
        new KeyValuePair<string, object>("ScopeKeyFour", "ScopeValueFour"),
        new KeyValuePair<string, object>("ScopeKeyFive", "ScopeValueFive"),
        new KeyValuePair<string, object>("ScopeKeySix", "ScopeValueSix"),
    }))
    {
        logger.Log<string>(LogLevel.Information, 0, null, null, Formatter);
    }
}

…isplay makes sense

- Supports multiple scopes each with keyvaluepairs displayed correctly
@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Merging #215 (2d38c4e) into main (6a2f6c5) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #215      +/-   ##
==========================================
+ Coverage   99.05%   99.12%   +0.06%     
==========================================
  Files           8        8              
  Lines         319      342      +23     
==========================================
+ Hits          316      339      +23     
  Misses          3        3              
Flag Coverage Δ
linux 98.24% <100.00%> (-0.82%) ⬇️
macos 99.12% <100.00%> (+0.06%) ⬆️
windows 99.12% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Logging.XUnit/XUnitLogScope.cs 100.00% <100.00%> (ø)
src/Logging.XUnit/XUnitLogger.cs 98.05% <100.00%> (+0.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a2f6c5...2d38c4e. Read the comment docs.

@martincostello martincostello added the enhancement New feature or request label Mar 26, 2021
Copy link
Owner

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also augment one of the new tests you've added with a scope that gets it to hit the uncovered block please?

src/Logging.XUnit/XUnitLogger.cs Outdated Show resolved Hide resolved
src/Logging.XUnit/XUnitLogger.cs Outdated Show resolved Hide resolved
src/Logging.XUnit/XUnitLogger.cs Outdated Show resolved Hide resolved
src/Logging.XUnit/XUnitLogger.cs Outdated Show resolved Hide resolved
tests/Logging.XUnit.Tests/XUnitLoggerTests.cs Outdated Show resolved Hide resolved
@martincostello martincostello added this to the v0.1.1 milestone Mar 26, 2021
@gkinsman
Copy link
Contributor Author

Could you also augment one of the new tests you've added with a scope that gets it to hit the uncovered block please?

Sure thing! I added a new test as having a scope type of IEnumerable<string> is different enough.

@martincostello martincostello merged commit 4ca0b65 into martincostello:main Mar 26, 2021
@martincostello
Copy link
Owner

Thanks for the PR George!

If you want to give it a whirl from MyGet to just check it's all working as you'd expect, then I'll push 0.1.1 to NuGet.org.

https://www.myget.org/feed/martincostello/package/nuget/MartinCostello.Logging.XUnit/0.1.1-beta0189

@gkinsman
Copy link
Contributor Author

Thanks for the PR George!

If you want to give it a whirl from MyGet to just check it's all working as you'd expect, then I'll push 0.1.1 to NuGet.org.

https://www.myget.org/feed/martincostello/package/nuget/MartinCostello.Logging.XUnit/0.1.1-beta0189

Perfect, was just wondering where I might get it from 😁. Will let you know how it goes! Thanks!

@gkinsman
Copy link
Contributor Author

So as I think you saw, it works well! Happy for you to push to nuget 🙂

@martincostello
Copy link
Owner

@gkinsman
Copy link
Contributor Author

Done! 🚀 https://www.nuget.org/packages/MartinCostello.Logging.XUnit/0.1.1

Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support IEnumerable<KeyValuePair<string, object>> as state object
2 participants