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

NLogBufferingTargetWrapperMiddleware for AspNetBufferingTargetWrapper #900

Merged
merged 8 commits into from
Dec 28, 2022

Conversation

bakgerman
Copy link
Contributor

@bakgerman bakgerman commented Dec 12, 2022

Resolves #304

  • Instead of each AspNetBufferingTargetWrapper injects itself into HttpContext.Items, then HttpModule / HttpMiddleware prepares an anchor-node where each AspNetBufferingTargetWrapper can register itself.
    • To avoid modifying HttpContext.Items during logging (since not threadsafe), and avoid AspNetBufferingTargetWrapper having to know about HttpModule / HttpMiddleware.
  • Introduces lazy allocation of request-buffering until target-logging actually occurs (possible performance benefit)

@bakgerman bakgerman changed the title Aspnetcore buffering wrapper - Single Commit Aspnetcore buffering wrapper - Less Commits Dec 12, 2022
@snakefoot
Copy link
Contributor

snakefoot commented Dec 12, 2022

@bakgerman Have attached minimal-changes version of AspNetBufferingTargetWrapper.cs here (Should resolve most of my comments):

AspNetBufferingTargetWrapper.zip

Hopefully GitHub will recognize it as a standard move-operation with minimal changes.

@bakgerman
Copy link
Contributor Author

Committed your version of AspNetBufferingTargetWrapper after reading the comments, changed NLogHttpModule to use OnEndRequest again

@bakgerman bakgerman changed the title Aspnetcore buffering wrapper - Less Commits ASP.NET buffering wrapper target Dec 13, 2022
@snakefoot
Copy link
Contributor

snakefoot commented Dec 13, 2022

Looks like GitHub is happy now, and sees AspNetBufferingTargetWrapper.cs as being moved.

But also need to revert the breaking changes in NLogHttpModule.cs.

@bakgerman
Copy link
Contributor Author

good comments, I will work on the unit tests later this week.

@bakgerman
Copy link
Contributor Author

bakgerman commented Dec 20, 2022

Thank you for pushing me for better unit tests. This did find 2 defects, one in null HttpContext case for NLogHttpModule, one for main success path in the core buffering target. DebugTarget and MemoryTarget were used to verify count of messages, that all all messages were written, and in proper order. A test case of 3 targets each having a memory target was the most complicated, and showed the messages in the proper order. When done with a valid HttpContext, the use of the buffer limit was proven. With a null HttpContext, the proof of skipping the buffer target and writing all messages even above the buffer limit was proven.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

90.8% 90.8% Coverage
0.0% 0.0% Duplication

@snakefoot
Copy link
Contributor

snakefoot commented Dec 20, 2022

Think the new test-cases looks great with asserting on the target-output, and not just probing the HttpContext-Items-Dictionary.

Unless you have other things you would like to add, then I think it is ready to merge (I will probably make a followup commit to merge the 2 test-classes into one common, and investigate not allocating HttpContextWrapper for every begin- / end-request.)

@snakefoot
Copy link
Contributor

@bakgerman After the merge the total code-coverage moved from 80pct to 84 pct, so nice improvement.

I guess the wiki-page needs to be updated, about how to use it with NLog.Web.AspNetCore:

https://github.com/NLog/NLog/wiki/AspNetBufferingWrapper-target

And maybe also the SandCastle docs:

https://nlog-project.org/documentation/v5.0.0/html/T_NLog_Web_Targets_Wrappers_AspNetBufferingTargetWrapper.htm

@bakgerman
Copy link
Contributor Author

Yes, I will update the wiki and SandCastle

@bakgerman bakgerman deleted the aspnetcore-buffering-wrapper2 branch December 29, 2022 02:13
@snakefoot
Copy link
Contributor

Think we can skip the SandCastle-docs for now, and focus on the wiki-page.

Still curious if there are any users waiting for AspNetBufferingTargetWrapper on ASP.NET Core, but I really like the new unit-tests.

@bakgerman
Copy link
Contributor Author

yes I am curious as well, i will focus on the wiki page.

@snakefoot snakefoot added this to the 5.2.1 milestone Dec 30, 2022
@bakgerman
Copy link
Contributor Author

wiki page is updated

@snakefoot
Copy link
Contributor

Excellent. Lets see if anyone will try the new rocket :)

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

Successfully merging this pull request may close these issues.

Port AspNetBufferingWrapper to ASP.NET Core
2 participants