-
Notifications
You must be signed in to change notification settings - Fork 1.4k
AspNet HttpContext Item Layout Renderer
Rolf Kristensen edited this page Dec 18, 2022
·
5 revisions
ASP.NET Item variable from HttpContext.Items
dictionary. Useful for storing state per request basis.
Platforms Supported: All
${aspnet-item:variable=String:objectpath=String:format=String}
-
item - Key for lookup in Items-dictionary (Required)
Introduced with NLog.Web v5.1, and replaces the
Variable
-option -
format - Format-specifier for converting the value as string (Optional)
Introduced with NLog.Web v5.0
-
culture - Culture-specifier for converting the value as string (Optional)
Introduced with NLog.Web v5.0
-
objectpath - Property path if the value is an object, also supports nested properties (Optional).
Introduced with NLog.Web v5.2 and replaces
EvaluateAsNestedProperties
-option
You can set the value of an ASP.NET Item variable by using the following code:
Example usage of ${aspnet-item}
HttpContext.Items["myvariable"] = 123;
HttpContext.Items["stringvariable"] = "aaa BBB";
HttpContext.Items["anothervariable"] = DateTime.Now;
${aspnet-item:variable=myvariable} - produces "123"
${aspnet-item:variable=anothervariable} - produces "01/01/2006 00:00:00"
${aspnet-item:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00"
${aspnet-item:variable=myvariable:padding=5} - produces " 123"
${aspnet-item:variable=myvariable:padding=-5} - produces "123 "
${aspnet-item:variable=stringvariable:upperCase=true} - produces "AAA BBB"
- 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