Skip to content

Latest commit

 

History

History
55 lines (38 loc) · 1.53 KB

README.md

File metadata and controls

55 lines (38 loc) · 1.53 KB

WPF.Appsettings - WPF

Logo

NuGet aiming to make it easier to use Microsoft.Extensions.Logging in WPF applications

Usage

Define WPF_ENVIRONMENT as an environment variable. For development this is typically Development:

<ItemGroup>
	<EmbeddedResource Include="appsettings.json" />
	<EmbeddedResource Include="appsettings.Development.json" Condition="'$(WPF_ENVIRONMENT)' == 'Development'" />
	<EmbeddedResource Include="appsettings.secrets.json" />
</ItemGroup>

You can then run this code to load one or two appsettings.json files with this code:

public sealed partial class App
{
    private static IConfiguration Configuration { get; } = new ConfigurationBuilder().AddAppsettings().Build();

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

		// From here, configuration is used exactly like in ASP.NET Core (minus the dependency injection of course)
        Debug.WriteLine(Configuration["Logging:LogLevel:Default"]);
    }
}

All appsettings.json files matching the following regex will be loaded:

(?<app_name>(?:\w+\.?)+)\.appsettings(?<environment>\.\w+)?\.json

Load order

  1. appsettings.json
  2. appsettings.{WPF_ENVIRONMENT}.json
  3. appsettings.local.json

Committing

Important to run this before committing (assuming you have GPG key set up)

git config commit.gpgsign true