-
Notifications
You must be signed in to change notification settings - Fork 1.4k
AspNet Response Headers Layout Renderer
Rolf Kristensen edited this page Aug 28, 2023
·
6 revisions
ASP.NET Response Headers key/value pairs.
Platforms Supported: All
Introduced in NLog.Web 5.1.0 and NLog.Web.AspNetCore 5.1.0
${aspnet-response-headers:items=String[]:outputFormat=Enum
:itemSeparator=String:valueSeparator=String
:valuesOnly=Boolean}
-
items - Header key name(s). A list of keys can be passed as comma separated values, e.g.:
Key1,Key2
(Not specified means all)Introduced with NLog.Web / NLog.Web.AspNetCore v5.2.1, and replaces the
headerNames
-option. -
exclude - Header key names to be excluded. A list of keys can be passed as comma separated values, e.g.:
Key1,Key2
-
outputFormat - Renders as flat string or as JSON. Default:
Flat
.-
Flat
- Key-value-pair as standard string -
JsonArray
- Key-value-pair in JSON-array -
JsonDictionary
- Key-value-pair as JSON-dictionary
-
-
itemSeparator - Separator between items. Default:
,
. Only applies when OutputFormat isFlat
. -
valueSeparator - Separator between value and key. Default:
=
. Only applies when OutputFormat isFlat
. -
ValuesOnly - Only render the values of the key/value pairs. Default:
false
. -
LowerCaseKeys - Convert Keys to lowercase. Default:
false
.Introduced in NLog.Web / NLog.Web.AspNetCore 5.1.1
Use this layout renderer to log the value of the specified headers(s) stored in the ASP.NET Response Headers collection.
In C# code:
Response.Headers["key1"] = "value1";
Response.Headers["id"] = "d4b20a34-6231-4201-83a6-c72599e41164";
${aspnet-response-headers:items=key1}
Will print:
"key1=value1"
${aspnet-response-headers:items=key1,id}
Will print:
"key1=value1,id=d4b20a34-6231-4201-83a6-c72599e41164"
${aspnet-response-headers:items=key1:OutputFormat=JSON}
Will print:
[{"key1":"value1"}]
${aspnet-response-headers:items=key1,id:OutputFormat=JSON}
Will print:
[{"key1":"value1","id":"d4b20a34-6231-4201-83a6-c72599e41164"}]
${aspnet-response-headers:items=key1:OutputFormat=JsonDictionary}
Will print:
{"key1":"value1"}
${aspnet-response-headers:items=key1:ValuesOnly=true}
Will print:
"value1"
${aspnet-response-headers:items=key1:OutputFormat=JSON:ValuesOnly=true}
Will print:
["value1"]
${aspnet-response-headers:items=key1,id:OutputFormat=JSON:ValuesOnly=true}
Will print:
["value1","d4b20a34-6231-4201-83a6-c72599e41164"]
- 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