Skip to content

AppSetting Layout Renderer

Rolf Kristensen edited this page Jun 13, 2019 · 11 revisions

Value from the App Settings configuration (app.config / web.config)

Platforms Supported: Limited (Not supported on Silverlight, Xamarin Android/iOS, NetCore)

NLog 4.6 has this included in the core NLog.dll for NetFramework (Not for NetCore that has ${configsetting})

NLog 3.0+ requires additional dependency on NLog.Extended

Configuration Syntax

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

Parameters

Rendering Options

  • item - Key in the apps setting. Required (NLog 4.5 and older used name)
  • Default - Default value if not present. Optional.

Example AppSettings

Example .config

<configuration>
  <appSettings>
    <add key="MyKey" value="MyApplication" />
  </appSettings>
</configuration>

Example renderer: produces MyApplication is this case:

${appsetting:item=MyKey:default=mydefault}

Example#2 renderer: produces mydefault is this case:

${appsetting:item=MyKey2:default=mydefault}

Example ConnectionStrings

Introduced with NLog 4.6.5

<configuration>
  <appSettings>
    <add key="MyKey" value="MyApplication" />
  </appSettings>
  <connectionStrings>
    <add name="ElasticUrl" connectionString="http://localhost:9200"/>
  </connectionStrings>
</configuration>

Example#3 renderer: produces http://localhost:9200 is this case:

${appsetting:item=connectionStrings.ElasticUrl}
Clone this wiki locally
You can’t perform that action at this time.