GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ConfigSetting Layout Renderer

ConfigSetting Layout Renderer

Jump to bottom Edit New page
Rolf Kristensen edited this page Oct 26, 2025 · 20 revisions

Lookup value from the appsettings.json or appsettings.Production.json and other configuration sources/overrides.

Introduced with NLog.Extensions.Logging 1.4.0 and NLog.Web.AspNetCore 4.8.0

Configuration Syntax

${configsetting:item=String:default=String}

Parameters

Rendering Options

  • item - Key in the config. Required. Use . for nested objects.
  • Default - Default value if not present. Optional.

Setup ConfigSetting

${configsetting} depends on Microsoft.Extensions.Configuration being loaded and available, so if using UseNLog() or AddNLog() on HostBuilder then everything will work out-of-the-box.

But if needing to load NLog configuration early before HostBuilder is ready, then ${configsetting} will not resolve the expected values, which might cause NLog Targets not using the expected configuration values. It is possible to setup ${configsetting} manually for these situations.

NLog Fluent Setup using LoadConfigurationFromAppSettings() from NLog.Web.AspNetCore nuget-package:

var logger = LogManager.Setup()
                       .LoadConfigurationFromAppSettings()
                       .GetCurrentClassLogger();

NLog Fluent Setup using LoadConfigurationFromSection(() from NLog.Extensions.Logging nuget-package:

IConfigurationRoot config = new ConfigurationBuilder()
    .AddJsonFile(path: "AppSettings.json").Build();
var logger = LogManager.Setup()
                       .LoadConfigurationFromSection(config)
                       .GetCurrentClassLogger();

NLog v4 can perform manual registration like this with NLog.Extensions.Logging nuget-package:

IConfigurationRoot config = new ConfigurationBuilder()
    .AddJsonFile(path: "AppSettings.json").Build();
NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = config;

Examples

Example: appsettings.json:

{
    "Mode":"Prod",
    "Options":{
        "StorageConnectionString":"UseDevelopmentStorage=true",
    }
}

Config Setting Lookup:

${configsetting:item=Mode} // renders "Prod"
${configsetting:item=Options.StorageConnectionString} // renders "UseDevelopmentStorage=true"
${configsetting:item=Options.TableName:default=MyTable} // renders "MyTable"

Config Setting Lookup Cached:

${configsetting:cached=True:item=Mode}

Notice appsettings.json gives the ability to make environment-specific overrides (Ex. appsettings.Production.json). See also Environment-specific-NLog-Logging-Configuration

- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config

Home

  • Getting started
    • NLog Introduction
    • Example - ASP.NET Core
    • Example - .NET Core Console
  • How to use structured logging
  • Troubleshooting
    • Internal Log
  • FAQ
  • Articles about NLog

Configuration

  • All targets, layouts and layout renderers
    Popular:
    • File-target
    • ColoredConsole-target
    • Database-target
    • Mail-target
  • Using NLog with NLog.config
  • Using NLog with appsettings.json

Programmatic Configuration

  • Configure from code
  • Sandcastle documentation

Advanced

  • Add LogEvent Context details
  • Filtering log messages
  • Optimize Logging Performance
  • NLog properties with Microsoft Extension Logging
  • NLog GetCurrentClassLogger and Microsoft ILogger
  • Using Time Sources
  • Installing targets
  • Visual Studio support
  • Who is using NLog
  • Advanced Examples

Extending NLog

  • Write custom extensions
  • How to write a custom target
  • How to write a custom layout renderer
  • Writing custom conditions
  • Properties constraints for custom extensions
  • Register your custom component

Clone this wiki locally

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.