-
Notifications
You must be signed in to change notification settings - Fork 1.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 needing NLog.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>
<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}
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.
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json