NLog.Appsettings.Standard 2.1.0

An NLog layout renderer be used to access appsettings.json.

Supported platforms:

- .NET Standard 1.6
- .NET Standard 2.0

Install-Package NLog.Appsettings.Standard -Version 2.1.0
dotnet add package NLog.Appsettings.Standard --version 2.1.0
<PackageReference Include="NLog.Appsettings.Standard" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NLog.Appsettings.Standard --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

An NLog layout renderer be used to access appsettings.json and supported .NET Standard 1.6/2.0.

Attention

The older package NLog.Appsetting.Standard is no longer updated and maintained. It is recommended to be replaced this new version.

How To Use

Install the NLog.Appsettings.Standard package from NuGet. You need add NLog 4.5 or higher, then put the syntax in your NLog configuration below:

<nlog>
    <extensions>
        <add assembly="NLog.Appsettings.Standard" />
    </extensions>
</nlog>

Configuration Syntax & Parameters

The layout renderer's name is appsettings, and syntax is ${appsettings:name=String.String2.String3:default=String}

  • name - Key in your appsettings.&lt;EnvironmentName&gt;.json file. If it has a multi-level hierarchy that you want to access, you can separate by a dot. Required.
  • default - Default value if not present. Optional.

Example

Target appsettings.json

{
    "Mode":"Prod",
    "Options":{
        "StorageConnectionString":"abcdefg123456789",
        "Container":"YourProdContainer"
    }
}
  • ${appsettings:name=Mode} - Get "Prod" in this case.
  • ${appsettings:name=Options.StorageConnectionString} - Get "abcdefg123456789" in this case.
  • ${appsettings:name=Options.StorageConnectionString2:default=DefaultString} - Get "DefaultString" in this case.

Set Explicit Configuration

In some cases, the library may not work correctly (e.g., always access incorrect appsettings.json). You can set the configuration directly by use the global property AppSettings before you start logging work as follows

using NLog.Appsettings.Standard;

..........

AppSettingsLayoutRenderer.AppSettings = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .AddJsonFile($"appsettings.Development.json", optional: true)
                         .Build();
..........

Note

If you need other NLog extensions(Target or Layout Renderer) that built by me or prefer all in one like me. You can refer this and its document!!!

An NLog layout renderer be used to access appsettings.json and supported .NET Standard 1.6/2.0.

Attention

The older package NLog.Appsetting.Standard is no longer updated and maintained. It is recommended to be replaced this new version.

How To Use

Install the NLog.Appsettings.Standard package from NuGet. You need add NLog 4.5 or higher, then put the syntax in your NLog configuration below:

<nlog>
    <extensions>
        <add assembly="NLog.Appsettings.Standard" />
    </extensions>
</nlog>

Configuration Syntax & Parameters

The layout renderer's name is appsettings, and syntax is ${appsettings:name=String.String2.String3:default=String}

  • name - Key in your appsettings.&lt;EnvironmentName&gt;.json file. If it has a multi-level hierarchy that you want to access, you can separate by a dot. Required.
  • default - Default value if not present. Optional.

Example

Target appsettings.json

{
    "Mode":"Prod",
    "Options":{
        "StorageConnectionString":"abcdefg123456789",
        "Container":"YourProdContainer"
    }
}
  • ${appsettings:name=Mode} - Get "Prod" in this case.
  • ${appsettings:name=Options.StorageConnectionString} - Get "abcdefg123456789" in this case.
  • ${appsettings:name=Options.StorageConnectionString2:default=DefaultString} - Get "DefaultString" in this case.

Set Explicit Configuration

In some cases, the library may not work correctly (e.g., always access incorrect appsettings.json). You can set the configuration directly by use the global property AppSettings before you start logging work as follows

using NLog.Appsettings.Standard;

..........

AppSettingsLayoutRenderer.AppSettings = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .AddJsonFile($"appsettings.Development.json", optional: true)
                         .Build();
..........

Note

If you need other NLog extensions(Target or Layout Renderer) that built by me or prefer all in one like me. You can refer this and its document!!!

Release Notes

1. Provide global configuration property that caller can pass the configuration they want use.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.1.0 7,755 1/10/2019
2.0.0 5,411 9/20/2018
1.0.0 6,721 8/29/2018