Relative path configuration in appsettings.json in .NET Core

805 views Asked by At

For sake of simplicity lets say we have the following structure of configuration files where I load all of them:

c:\apps\myapp\appsettings.json
c:\apps\appsettings.json
c:\appsettings.json

The configuration "schema" looks like this:

{
  "logPath": "c:\\apps\\logs"
}

Instead of giving absolute path of log folder, I would like to give relative one like .\\logs where . would be current configuration file. While debugging I discovered that IConfigurationRoot contains all those configuration sources (in this case JsonConfigurationSource) which contains path to configuration file, but I didn't find any way how to get ConfigurationSource for specific key. So Something like IConfigurationRoot.GetConfigurationSource(string key).

Is there any way how to get configuration source for specific key? Or maybe some other way to use relative paths?

0

There are 0 answers