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

Add Reqnroll.Microsoft.Extensions.Logging.ReqnrollPlugin #321

Merged
merged 6 commits into from
Feb 10, 2025

Conversation

StefH
Copy link
Contributor

@StefH StefH commented Nov 8, 2024

🤔 What's changed?

As discussed here #247
I've created a new projects which cn be used to forward the logging from an ILogger to IReqnrollOutputHelper.

⚡️ What's your motivation?

#247

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

Initial code, please provide feedback.
And should this be called a "Plugin" because it does not actually implement IRuntimePlugin.

📋 Checklist:

  • I've changed the behaviour of the code
  • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Users should know about my change
  • I have added an entry to the "[vNext]" section of the CHANGELOG, linking to this pull request & included my GitHub handle to the release contributors list.

@clrudolphi
Copy link
Contributor

Interesting idea. I'd like your thoughts on a related effort. We're considering adding use of Microsoft Logging internal to Reqnroll, to be used by Reqnroll maintainers and developers of Plugins, to obtain Trace and Debug-level output. This would be used to understand what's going on within the Reqnroll engine. The idea, though, is to steer such output away from the Test Framework's output stream (aka, avoid calling IReqnrollOutputHelper) so that the internal debug output doesn't interfere with the usual output of the Tests themselves.

With that description, would you think your approach for this plugin would need to be different?
How should we approach using and configuring MS Logging so that two use cases remain separated and don't intermix their log outputs?

@StefH
Copy link
Contributor Author

StefH commented Nov 9, 2024

Hello @Tiberriver256 and @gasparnagy,

The idea for this PR is based on this project:

And I use this in my project to view the logging directly in the testoutput when running my tests locally, but specifically when running in Azure DevOps.


I think that your approach of adding Microsoft Logging to Reqnroll is the other way around.

@gasparnagy
Copy link
Contributor

This is definitely useful. I will have a busy week, so I can play with it only in the week after. I would like to keep this open until then. (So if we need further hotfix for v2.2 we can easier apply.)

@gasparnagy
Copy link
Contributor

For using it internally the challenge is to have a specific version of Microsoft.Extensions.Logging.Abstractions bound to Reqnroll.

E.g. If the project that is being tested uses Microsoft.Extensions.Logging.Abstractions 6.0, how much trouble we will cause if we force it to be 8.0.

@StefH Do you know other tool similar to Reqnroll that use it internally and hence influence the dependencies of the product being tested?

@StefH
Copy link
Contributor Author

StefH commented Nov 9, 2024

This is definitely useful. I will have a busy week, so I can play with it only in the week after. I would like to keep this open until then. (So if we need further hotfix for v2.2 we can easier apply.)

That's ok.
Note that for now it's still a draft PR because I'm not sure if the code + tests conform to this project. If you have time you can already add some comments on my code.

@StefH
Copy link
Contributor Author

StefH commented Nov 9, 2024

For using it internally the challenge is to have a specific version of Microsoft.Extensions.Logging.Abstractions bound to Reqnroll.

E.g. If the project that is being tested uses Microsoft.Extensions.Logging.Abstractions 6.0, how much trouble we will cause if we force it to be 8.0.

@StefH Do you know other tool similar to Reqnroll that use it internally and hence influence the dependencies of the product being tested?

In case you really want be most compatible, add the .NET 8.0 also as a framework and in that case use Microsoft.Extensions.Logging.Abstractions version 8.
Else use version 6.
For an example see: 7abaf11


But I've another question:
Why do you use custom .nuspec files instead of defining everything in the .csproj?
To my opinion, custom .nuspec files are more difficult to maintain, especially when targeting multiple frameworks.

@StefH StefH marked this pull request as ready for review November 29, 2024 17:05
@DrEsteban
Copy link
Contributor

For using it internally the challenge is to have a specific version of Microsoft.Extensions.Logging.Abstractions bound to Reqnroll.

E.g. If the project that is being tested uses Microsoft.Extensions.Logging.Abstractions 6.0, how much trouble we will cause if we force it to be 8.0.

In case you really want be most compatible, add the .NET 8.0 also as a framework and in that case use
Microsoft.Extensions.Logging.Abstractions version 8.
Else use version 6.
For an example see: 7abaf11

+1 on this as a way to handle it. I also believe, in general, it's recommended to target the oldest version possible in the compatibility list for a particular library. Microsoft generally tries to maintain compatibility as versions increase (e.g. 6.0 -> 8.0), but not necessarily the other way around if new features/types are introduced.

So if Reqnroll can compile against Microsoft.Extensions.Logging.Abstractions v6.0, meaning it doesn't use any new features/types in 8.0, that's generally a better idea as it's much safer to redirect the version forward rather than backward.

Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

This looks good.

I'm just thinking how we could somehow provide an even deeper support for the logging with this.

Could you please paste a sample code (e.g. a sample step definition class) that uses this logger? Based on that I might get some additional ideas.

@@ -0,0 +1,9 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="TaskFolder;TaskAssembly">
<ItemGroup>
<None Include="$(_Reqnroll_MicrosoftExtensionsLoggingPluginPath)" >
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is not a real Reqnroll "plugin", but just a library, do we still need to copy the assembly like that?

Copy link
Contributor Author

@StefH StefH Feb 5, 2025

Choose a reason for hiding this comment

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

It's not a real plugin indeed.
Should I remove this while file?

@StefH
Copy link
Contributor Author

StefH commented Feb 5, 2025

This looks good.

I'm just thinking how we could somehow provide an even deeper support for the logging with this.

Could you please paste a sample code (e.g. a sample step definition class) that uses this logger? Based on that I might get some additional ideas.

Example project can be found here:
https://github.com/StefH/Stef.Extensions.SpecFlow.Logging/tree/add-reqnroll/test

Example output in VS:

 Add two numbers
   Source: Calculator.feature line 5
   Duration: 53 ms

  Standard Output: 
Given the first number is 50
-> done: CalculatorStepDefinitions.GivenTheFirstNumberIs(50) (0,0s)
And the second number is 70
-> done: CalculatorStepDefinitions.GivenTheSecondNumberIs(70) (0,0s)
When the two numbers are added
-> Adding 50 and 70
-> done: CalculatorStepDefinitions.WhenTheTwoNumbersAreAdded() (0,0s)
Then the result should be 120
-> done: CalculatorStepDefinitions.ThenTheResultShouldBe(120) (0,0s)
-> duration: Scenario: Add two numbers: 49,5ms

The -> Adding 50 and 70 is from the Ilogger

@gasparnagy
Copy link
Contributor

@StefH Have you seen any "manual" usage of the logger without the MSDI? If yes, how would that usage look like?

I am asking, because (as we discussed earlier) the usage of this with MSDI has problems with parallel execution. This is not because of the logging code (that is fine), but because of how the Reqnroll MSDI extension currently works.

Maybe when the Reqnroll MSDI extension is updated, we can make this really a plugin and users would not even need to do the registration, so the usage will change and we would need to deal with that breaking change. When we include it, we should include it with the final usage version.

The following options are in my mind:

  1. Postpone this entirely until the MSDI extension is updated and we know more about it.
  2. Include it to the Reqnroll codebase as it is, but do not publish it to NuGet
  3. Include the code into the MSDI extension project and package. (This package will change significantly anyway, so the breaking changes related to the logger might not be that painful when they happen.)

What do you think?

@StefH
Copy link
Contributor Author

StefH commented Feb 8, 2025

a]
I did not see / did not use any manual.

b]
My personal preference would be option 2. (this will also give other developers time to review)
And then wait on the MSDI extension is updated and finalized.

@gasparnagy
Copy link
Contributor

@StefH OK. Based on your first answer, I think I would include it now to the MSDI extension project, but do not advertise too much. I think this helps to consider this as a whole together with the MSDI extension, and also if someone wants to use it, they can. It is a useful piece of code anyway. Separating it is anyway easier than merging it.
I will handle this.

Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

Thx. As discussed I proceed.

@gasparnagy gasparnagy merged commit a3ec015 into reqnroll:main Feb 10, 2025
5 checks passed
@gasparnagy
Copy link
Contributor

@StefH Thank you for the contribution! According to our guidelines I have invited you to the Reqnroll contributors team. Congrats! 🎉 If you accept it, you will be able to make pull requests easier in the future.

You are also welcome on our discord server: https://go.reqnroll.net/discord-invite

@StefH StefH deleted the stef/logging branch February 10, 2025 12:16
@StefH
Copy link
Contributor Author

StefH commented Feb 10, 2025

@gasparnagy
Thank you for invite, but the link to "contributors team" leads to 404?

@gasparnagy
Copy link
Contributor

Strange. For me it works. https://github.com/orgs/reqnroll/teams/contributors/members

Maybe because you haven't accepted the invitation yet?

@gasparnagy
Copy link
Contributor

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

Successfully merging this pull request may close these issues.

4 participants