Skip to content

AspNetRequest QueryString Layout Renderer

Rolf Kristensen edited this page Aug 28, 2023 · 19 revisions

ASP.NET Request Query String key/value pairs.

Platforms Supported: All

Introduced in NLog.Web 4.3

Configuration Syntax

${aspnet-request-querystring:items=String:outputFormat:Enum
    :itemSeparator=String:valueSeparator=String
    :valuesOnly=Boolean}

Parameters

Rendering Options

  • items - Query String key(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 queryStringKeys-option.

    With NLog.Web / NLog.Web.AspNetCore v4.3.1 then all key/value pairs will be rendered, when not specified.

  • exclude - Query String key names to be excluded. A list of keys can be passed as comma separated values, e.g.: Key1,Key2

    Introduced with NLog.Web v5.2.2

Formatting options

  • outputFormat - Renders as flat string or as JSON. Default: Flat.
    • Flat - Key-value-pair as standard string
    • JsonArray - Key-value-pair in JSON-array (Introduced with NLog 5.0, replaces now obsolete Json)
    • JsonDictionary - Key-value-pair as JSON-dictionary. (Introduced with NLog 5.0, replaces now obsolete singleAsArray)
  • itemSeparator - Separator between items. Default: ,. Only applies when OutputFormat is Flat.

    Introduced in NLog.Web.AspNetCore 4.4 / NLog.Web 4.5

  • valueSeparator - Separator between value and key. Default: =. Only applies when OutputFormat is Flat.

    Introduced in NLog.Web.AspNetCore 4.4 / NLog.Web 4.5

  • ValuesOnly - Only render the values of the key/value pairs. Default: false.

    Introduced in NLog.Web / NLog.Web.AspNetCore v4.6

  • LowerCaseKeys - Convert Keys to lowercase. Default: false.

    Introduced in NLog.Web / NLog.Web.AspNetCore v5.1.1

Remarks

Use this layout renderer to insert the value of the specified query string parameters stored in the ASP.NET Query String collection.

Examples

In C# code:

Response.Redirect("myPage.aspx?key1=value1&id=d4b20a34-6231-4201-83a6-c72599e41164");

Log single query string key/value pair in default Flat output format

${aspnet-request-querystring:items=key1}

Will print:

"key1=value1"

Log multiple query string key/value pairs in default Flat output format

${aspnet-request-querystring:items=key1,id}

Will print:

"key1=value1,id=d4b20a34-6231-4201-83a6-c72599e41164"

Log single query string key/value pair in JSON output format

${aspnet-request-querystring:items=key1:OutputFormat=JSON}

Will print:

[{"key1":"value1"}]

Log multiple query string key/value pairs in JSON output format

${aspnet-request-querystring:items=key1,id:OutputFormat=JSON}

Will print:

[{"key1":"value1","id":"d4b20a34-6231-4201-83a6-c72599e41164"}]

Log single query string key/value pair as JSON dictionary:

${aspnet-request-querystring:items=key1:OutputFormat=JsonDictionary}

Will print:

{"key1":"value1"}

Log single query string key/value pair in Flat output format as value only

${aspnet-request-querystring:items=key1:ValuesOnly=true}

Will print:

"value1"

Log single query string key/value pair in JSON output format as value only

${aspnet-request-querystring:items=key1:OutputFormat=JSON:ValuesOnly=true}

Will print:

["value1"]

Log multiple query string key/value pairs in JSON output format as value only

${aspnet-request-querystring:items=key1,id:OutputFormat=JSON:ValuesOnly=true}

Will print:

["value1","d4b20a34-6231-4201-83a6-c72599e41164"]
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy