Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/NLogPublic

AspNetRequest Form Layout Renderer

Rolf Kristensen edited this pageAug 28, 2023 ·10 revisions

ASP.NET Request Form key/value pairs.

Platforms Supported:All

Introduced in NLog.Web 4.7

Configuration Syntax

${aspnet-request-form:items=String[]:exclude=String[]:outputFormat=Enum    :itemSeparator=Layout:valueSeparator=Layout    :valuesOnly=Boolean}

Parameters

Rendering Options

  • items - Form 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.2, and replaces theinclude-option.

  • exclude - Form key name(s) to exclude from the output. A list of keys can be passed as comma separated values, e.g.:Key1,Key2.

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 obsoleteJson)
    • JsonDictionary - Key-value-pair as JSON-dictionary. (Introduced with NLog 5.0, replaces now obsoletesingleAsArray)
  • 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

Remarks

Use this layout renderer to log the ASP.NET Request Form collection.

Examples

In C# code:

httpContext.Request.Form=newFormCollection(newDictionary<string,StringValues>{{"id","1"},{"name","Test Person"},{"token","86abe8fe-2237-4f87-81af-0a4e522b4140"}});

Log all Form data from the Request in default Flat output format

${aspnet-request-form}

Will print:

"id=1,name=Test Person,token=86abe8fe-2237-4f87-81af-0a4e522b4140"

Log all Form data from the Request in JSON output format

${aspnet-request-form:OutputFormat=JSON}

Will print:

[{"id":"1"},{"name":"Test Person"},{"token":"86abe8fe-2237-4f87-81af-0a4e522b4140"}]

Log only the specified Form keys from the Request in default Flat output format

${aspnet-request-form:items=id,name}

Will print:

"id=1,name=Test Person"

Log all Form data from the Request except for the specified keys in default Flat output format

${aspnet-request-form:Exclude=token}

Will print:

"id=1,name=Test Person"

Log all Form data from the Request in Flat output format with each item separated by a new line

${aspnet-request-form:ItemSeparator=${newline}}

Will print:

"id=1\r\nname=Test Person\r\ntoken=86abe8fe-2237-4f87-81af-0a4e522b4140"

-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config

Configuration

Programmatic Configuration

Advanced

Extending NLog

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp