i have an app in which i would like to configure NLog with a configuration file like this
services.AddLogging(loggingBuilder =>
{
loggingBuilder
.ClearProviders()
.AddNLog(projectInfo.GetNLogConfigPath())
.AddFilter("Microsoft", LogLevel.Warning);
})
However i would like to get this file location from a singleton service from DI. I searched for a service provider but all i found is the loggingBuilder service collection (for now projectInfo is a local variable).
Is there a way to get service provider in the AddLogging extension method action ?
You can use this
AddNLog()extension method from NLog.Extensions.LoggingThen you have this appsettings.json:
Notice you could also just have the NLog-configuration in the appsettings.json.