AppSetting Layout Renderer
Value from the App Settings configuration (app.config / web.config)
Platforms Supported: Limited (.NET Framework only, when using .NET Core then ${configsetting} can be used to read values from
appsettings.json-file)
Introduced with NLog 3.0 and with NLog 4.6+ it was included in default NLog-package without needing NLog.Extended.
Configuration Syntax
${appsetting:item=String:default=String}
Parameters
Rendering Options
-
item - Key in the apps setting. Required
Introduced with NLog v4.5, and replaces the
Name-option. - 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}
Note remember to uninstall/remove NLog.Extended-nuget-package from the application when having upgraded to NLog v4.6.5, else connectionStrings-lookup will not work.