- Notifications
You must be signed in to change notification settings - Fork1.4k
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 needingNLog.Extended.
${appsetting:item=String:default=String}- 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 .config
<configuration> <appSettings> <addkey="MyKey"value="MyApplication" /> </appSettings></configuration>
Example renderer: producesMyApplication is this case:
${appsetting:item=MyKey:default=mydefault}Example#2 renderer: producesmydefault is this case:
${appsetting:item=MyKey2:default=mydefault}Introduced with NLog 4.6.5
<configuration> <appSettings> <addkey="MyKey"value="MyApplication" /> </appSettings> <connectionStrings> <addname="ElasticUrl"connectionString="http://localhost:9200"/> </connectionStrings></configuration>
Example#3 renderer: produceshttp://localhost:9200 is this case:
${appsetting:item=connectionStrings.ElasticUrl}Note remember to uninstall/removeNLog.Extended-nuget-package from the application when having upgraded to NLog v4.6.5, else connectionStrings-lookup will not work.
-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config
- All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json