Skip to content

Add IHostApplicationBuilder support#780

Merged
snakefoot merged 2 commits intoNLog:masterfrom
mikezw:master
May 23, 2025
Merged

Add IHostApplicationBuilder support#780
snakefoot merged 2 commits intoNLog:masterfrom
mikezw:master

Conversation

@mikezw
Copy link
Copy Markdown
Contributor

@mikezw mikezw commented May 22, 2025

Hi, I add a support of IHostApplicationBuilder, so we can use IHostApplicationBuilder.UseNLog() after net8.0, but there is an issue when run bothUseNLog_LoadConfigurationFromSection and IHostApplicationBuilder_UseNLog_LoadConfigurationFromSection in tests. one will failed, Could anyone help take a look?

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.39%. Comparing base (165b24f) to head (727439b).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #780      +/-   ##
==========================================
- Coverage   81.58%   81.39%   -0.19%     
==========================================
  Files          19       19              
  Lines        1765     1774       +9     
  Branches      315      315              
==========================================
+ Hits         1440     1444       +4     
- Misses        182      187       +5     
  Partials      143      143              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@snakefoot
Copy link
Copy Markdown
Contributor

snakefoot commented May 22, 2025

I think it looks great. And it seems you have solved the issue with global-state bleeding into the next test (by clearing global state)

One could consider to introduce UseNLog(...)-methods that supports isolated LogFactory-instance, instead of the global LogManager-singleton.

public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder builder, NLogProviderOptions options, Func<IServiceProvider, LogFactory> factoryBuilder)

@snakefoot
Copy link
Copy Markdown
Contributor

Do you expect any more changes, or is it ready to merge?

@mikezw
Copy link
Copy Markdown
Contributor Author

mikezw commented May 23, 2025

Hi, I see the codes here
I can add the extensions but I have no idea on how to test it, or you can merge this and I will open another pr to add

public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder builder, NLogProviderOptions options, Func<IServiceProvider, LogFactory> factoryBuilder)
public static IHostBuilderr UseNLog(this IHostBuilder builder, NLogProviderOptions options, Func<IServiceProvider, LogFactory> factoryBuilder)

And I have a question, what will happen after I add the factoryBuilder in above api and ILoggingBuilder.AddNLog(factoryBuilder), are these two methods equivalent?

Maybe in IHostApplicationBuilder we can use the IHostApplicationBuilder.Logging property whitch type is ILoggingBuilder

@mikezw
Copy link
Copy Markdown
Contributor Author

mikezw commented May 23, 2025

Hi, I was defeated by these providers, factories and builders. It might be a little difficult for me.

@snakefoot
Copy link
Copy Markdown
Contributor

snakefoot commented May 23, 2025 via email

@snakefoot snakefoot merged commit 909404c into NLog:master May 23, 2025
3 checks passed
@snakefoot
Copy link
Copy Markdown
Contributor

snakefoot commented May 23, 2025

@mikezw I'm planning to get this released with NLog v5.5, before starting to update NLog.Extensions.Logging + NLog.Web.AspNetCore for NLog v6 RTM (making breaking changes)

I expect to release NLog v5.5 within the next 1-2 weeks. I hope this works for you?

P.S. Created #782 with support for isolated LogFactory

@mikezw
Copy link
Copy Markdown
Contributor Author

mikezw commented May 26, 2025

Thank you very much. I will use it as soon as it is released

@snakefoot
Copy link
Copy Markdown
Contributor

NLog.Extensions.Logging v5.5 has been released to nuget:

Thank you again for the contribution.

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.

3 participants