Closed IanKemp closed 2 years ago
The whole point of using this package for .NET Core users, would be to use appsettings.json
The main reason for using NLog.Extensions.Logging
-nuget-package is actually to register NLog as logging-provider in the Microsoft-Extension-Logging-Framework (See AddNLog
- and UseNLog
-methods). This will redirect the output from MEL-ILogger to NLog Targets together with NLog Layout- and Filtering-logic.
Happy that you are excited about the ability to load NLog-configuration from the appsettings.json
. NLog was created before NetCore was invented and when XML was crazy new. There is an insane amount of information about how to use NLog.config
, and all that advice still works on NetCore.
Trying to convince everyone that they now need to run in a new direction is not easy. Users like when things are similar to before and predictable. The support for loading NLog-configuration from the appsettings.json
was just "recently" added, and it still need to pick up some traction. Very few blog-articles on the Internet are singing its praise, so remains somewhat hidden. It will require a lot of work to provide the same level of documentation for appsettings.json
, which already exists for NLog.config
.
I have tried to make the support more visible by introducing the NLog.LogManager.Setup()
where NLog.Web.AspNetCore provides this ability:
var logger = LogManager.Setup()
.LoadConfigurationFromAppSettings()
.GetCurrentClassLogger();
Extra dependencies are necessary for loading the appsettings.json
-file, and are not included in the NLog.Extensions.Logging-nuget-package.
At the very least, would you be open to adding something to the README along the lines of "documentation for appsettings.json is WIP, here's a link to an example project" and link to https://github.com/NLog/NLog.Extensions.Logging/tree/master/examples/NetCore2/ConsoleExampleJsonConfig ?
@IanKemp All Wiki-pages in the NLog-project are open for editing. Some times a wiki-page is deleted (by accident?), but most of the time people are improving the docs.
@snakefoot My question is related to appsetting.json, so I decided to ask it here instead of creating new one - I'm struggling to understand how can I replicate below xml configuration in json:
<logger name="Connection" minLevel="Info" writeTo="heartbeatFile,console" final="true">
<filters defaultAction="Ignore">
<when condition="contains('${message}','HeartbeatRequest')" action="Log"/>
<when condition="contains('${message}','HeartbeatResponse')" action="Log"/>
</filters>
</logger>
Please create new issue with your question, instead of piggy backing. Thank you for creating #491
All tutorials for AspNetCore have now been updated to use NLog.LogManager.Setup().LoadConfigurationFromAppSettings()
.
The tutorial for simple console application has also been updated with loggingBuilder.AddNLog(config);
Closing as resolved.
The whole point of using this package for .NET Core users, would be to use
appsettings.json
to define logging targets and rules. However the "getting started" articles in the README all use the legacynlog.config
to define the logging setup. These should be updated to useappsettings.json
, as per the example at https://github.com/NLog/NLog.Extensions.Logging/tree/master/examples/NetCore2/ConsoleExampleJsonConfig