-
Notifications
You must be signed in to change notification settings - Fork 150
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
Allow me to fully configure logging using Microsoft.Extensions.Configuration #294
Comments
Not sure I understand configuring logging without a dependency to NLog. You can read appsettings.json and read the NLog-config like this: var config = new ConfigurationBuilder()
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
LogManager.Configuration = new NLogLoggingConfiguration(config.GetSection("NLog"));
var hostBuilder = new HostBuilder() Extracted from: See also: https://github.com/NLog/NLog.Extensions.Logging/wiki/Json-NLog-Config Think you have to show some code examples (or even better make a PR that implements your ideas). |
Oops, that seems exactly what I was looking for. I somehow just didn’t manage to find it. 😊 I think at some point I even looked at that example but turned away because that sample still has that nlog.config XML file. Is that XML file needed for the example? Is it actually being loaded? Also, is there a way to get rid of that global exception handler that calls We would like to wrap everything that is needed to configure and use NLog into a single extension method for The users of our application framework who chose to use Nlog would just call the extension methods once in their Program.cs on their |
I guess one could create a new NLogLoggingConfiguration-parameter that causes the NLogLoggerProvider to call LogManager.Shutdown() on Dispose(): NLog.Extensions.Logging/src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs Lines 83 to 89 in 931cfbe
Instead of calling Flush(). |
Should this be done in the NLog repo? Or should I roll my own subclass? If I were to submit a PR for this, would it get accepted? |
If the default value of the new NLogLoggingConfiguration-parameter is NOT to shutdown, then I think it will be accepted if you create a PR for this repository. |
Can confirm that :) |
Extracted the todo into this: #313 |
@bitbonk NLog.Extension.Logging ver. 1.5.2 has been released that allows you to configure the option You can add it to your appsettings.json like this (or explicitly in code by initializing {
"Logging": {
"NLog": {
"shutdownOnDispose": true
}
}
} See also #314 |
Type: Feature request
In an application that is using the Microsoft generic host infrastructure (
Microsoft.Extensions.Hosting
) that comes with its own configuration system (Microsoft.Extensions.Configuration
) it is currently not possible to useMicrosoft.Extensions.Configuration
to fully configure NLog logging.I have to either use an nlog.config file or use the
NLog.Config
APIs to do the the configuration in code.In our applications anything that needs to be configured must always be done through
Microsoft.Extensions.Configuration
, including but not limited to logging.I am aware that there is the ConfigSettingsLayoutRender but since this is just a renderer its use is very limited.
Some examples of what we would like to be able to do in external configuration sources:
Microsoft.Extensions.Configuration
without needing a dependency to NLog).The text was updated successfully, but these errors were encountered: