Click or drag to resize

AspNetHttpContextItemLayoutRenderer Class

ASP.NET HttpContext Items Dictionary Value.
Inheritance Hierarchy
SystemObject
  NLog.LayoutRenderersLayoutRenderer
    NLog.Web.LayoutRenderersAspNetLayoutRendererBase
      NLog.Web.LayoutRenderersAspNetHttpContextItemLayoutRenderer

Namespace:  NLog.Web.LayoutRenderers
Assemblies:   NLog.Web.AspNetCore (in NLog.Web.AspNetCore.dll) Version: 6.0.0+59339f2811712b446adf6dcd8a6bad39ad9f2ba1
  NLog.Web (in NLog.Web.dll) Version: 6.0.0+59339f2811712b446adf6dcd8a6bad39ad9f2ba1
Syntax
public class AspNetHttpContextItemLayoutRenderer : AspNetLayoutRendererBase

The AspNetHttpContextItemLayoutRenderer type exposes the following members.

Constructors
  NameDescription
Public methodAspNetHttpContextItemLayoutRenderer
Initializes a new instance of the AspNetHttpContextItemLayoutRenderer class
Top
Properties
  NameDescription
Public propertyCulture
Gets or sets the culture used for rendering.
Public propertyFormat
Format string for conversion from object to string.
Public propertyHttpContextAccessor
Provides access to the current request HttpContext.
(Inherited from AspNetLayoutRendererBase.)
Public propertyItem
Gets or sets the item variable name.
Protected propertyLoggingConfiguration
Gets the logging configuration this target is part of.
(Inherited from LayoutRenderer.)
Public propertyObjectPath
Gets or sets the object-property-navigation-path for lookup of nested property. In this case the Item should have have any dot notation, as the nested properties path is in this variable Example: Item="person"; ObjectPath="Name.First" This will emit the First Name property of the object in HttpContext.Items woith the key of 'person' in the collection
Protected propertyValueFormatter
Value formatter
(Inherited from LayoutRenderer.)
Public propertyVariable Obsolete.
Gets or sets the item variable name.
Top
Methods
  NameDescription
Protected methodAppend
Renders the value of layout renderer in the context of the specified log event into StringBuilder.
(Overrides AspNetLayoutRendererBaseAppend(StringBuilder, LogEventInfo).)
Protected methodCloseLayoutRenderer
Closes the layout renderer.
(Inherited from AspNetLayoutRendererBase.)
Protected methodDoAppend Obsolete.
Renders the value of layout renderer in the context of the specified log event into StringBuilder.
(Inherited from AspNetLayoutRendererBase.)
Protected methodGetCulture
Get the CultureInfo for rendering the messages to a String
(Inherited from LayoutRenderer.)
Protected methodGetFormatProvider
Get the IFormatProvider for rendering the messages to a String
(Inherited from LayoutRenderer.)
Protected methodInitializeLayoutRenderer
Initializes the layout renderer.
(Overrides LayoutRendererInitializeLayoutRenderer.)
Public methodRender
Renders the value of layout renderer in the context of the specified log event.
(Inherited from LayoutRenderer.)
Protected methodResolveServiceT
Resolves the interface service-type from the service-repository
(Inherited from LayoutRenderer.)
Public methodToString
Returns a string that represents the current object.
(Inherited from LayoutRenderer.)
Top
Remarks
1${aspnet-httpcontext-item:myKey} - produces "123"
2${aspnet-httpcontext-item:anotherKey} - produces "01/01/2006 00:00:00"
3${aspnet-httpcontext-item:anotherKey:culture=pl-PL} - produces "2006-01-01 00:00:00"
4${aspnet-httpcontext-item:myKey:padding=5} - produces "  123"
5${aspnet-httpcontext-item:myKey:padding=-5} - produces "123  "
6${aspnet-httpcontext-item:stringKey:upperCase=true} - produces "AAA BBB"
Examples

You can set the value of an ASP.NET Item variable by using the following code:

C#
1HttpContext.Current.Items["myKey"] = 123;
2HttpContext.Current.Items["stringKey"] = "aaa BBB";
3HttpContext.Current.Items["anotherKey"] = DateTime.Now;
See Also