NLog.Web Provides the HttpContext associated with the current request. HttpContext of the current request. Provides access to the HttpContext HttpContext associated with the current request ASP.NET Application variable. Use this layout renderer to insert the value of the specified variable stored in the ASP.NET Application dictionary. You can set the value of an ASP.NET Application variable by using the following code: Example usage of ${aspnet-application}: ${aspnet-application:variable=myvariable} - produces "123" ${aspnet-application:variable=anothervariable} - produces "01/01/2006 00:00:00" ${aspnet-application:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00" ${aspnet-application:variable=myvariable:padding=5} - produces " 123" ${aspnet-application:variable=myvariable:padding=-5} - produces "123 " ${aspnet-application:variable=stringvariable:upperCase=true} - produces "AAA BBB" Gets or sets the variable name. Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. Rendering Application BasePath. ("~") Append to target The to append the rendered data to. Logging event. ASP.NET Item variable. Use this layout renderer to insert the value of the specified variable stored in the ASP.NET HttpContext.Current.Items dictionary. You can set the value of an ASP.NET Item variable by using the following code: Example usage of ${aspnet-item}: ${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" Initializes a new instance of the class. Gets or sets the item variable name. Gets or sets whether items with a dot are evaluated as properties or not Gets or sets the culture used for rendering. Renders the specified ASP.NET Item value and appends it to the specified . The to append the rendered data to. Logging event. Layout renderers for ASP.NET rendering multiple key/value pairs. Separator between item. Only used for Render with Separator between value and key. Only used for Render with Single item in array? Only used for Mutliple items are always in an array. Determines how the output is rendered. Possible Value: FLAT, JSON. Default is FLAT. Only render values if true, otherwise render key/value pairs. Serialize multiple key/value pairs The key/value pairs. Add to this builder. Serialize multiple key/value pairs The key/value pairs. Add to this builder. Log event for rendering separators. Get the rendered Get the rendered Append the value quoted, escape quotes when needed Base class for ASP.NET layout renderers. Context for DI Provides access to the current request HttpContext. HttpContextAccessor or null Validates that the HttpContext is available and delegates append to subclasses.. The to append the rendered data to. Logging event. Implemented by subclasses to render request information and append it to the specified . Won't be called if of is null. The to append the rendered data to. Logging event. Register a custom layout renderer with a callback function . The callback recieves the logEvent and the current configuration. Name of the layout renderer - without ${}. Callback that returns the value for the layout renderer. ASP.NET MVC Controller Name. Use this layout renderer to render the controller name. ${aspnet-mvc-action} Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. The current http context. ASP.NET MVC Controller Name. Use this layout renderer to render the controller name. ${aspnet-mvc-controller} Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. The current http context. Base Class for ASP.NET MVC Renderer. Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. The current http context. ASP.NET HttpRequest Content-Type Header ${aspnet-request-contenttype} Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Request Cookie Example usage of ${aspnet-request-cookie} ${aspnet-request-cookie:OutputFormat=Flat} ${aspnet-request-cookie:OutputFormat=Json} ${aspnet-request-cookie:OutputFormat=Json:CookieNames=username} ${aspnet-request-cookie:OutputFormat=Json:Exclude=access_token} Cookie names to be rendered. If null or empty array, all cookies will be rendered. Gets or sets the keys to exclude from the output. If omitted, none are excluded. Initializes a new instance of the class. Renders the ASP.NET Cookie appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Request Form Data Example usage of ${aspnet-request-form}: ${aspnet-request-form} - Produces - All Form Data from the Request with each key/value pair separated by a comma. ${aspnet-request-form:Include=id,name} - Produces - Only Form Data from the Request with keys "id" and "name". ${aspnet-request-form:Exclude=id,name} - Produces - All Form Data from the Request except the keys "id" and "name". ${aspnet-request-form:Include=id,name:Exclude=id} - Produces - Only Form Data from the Request with key "name" ( takes precedence over ). ${aspnet-request-form:ItemSeparator=${newline}} - Produces - All Form Data from the Request with each key/value pair separated by a new line. Gets or sets the form keys to include in the output. If omitted, all are included. takes precedence over . Gets or sets the form keys to exclude from the output. If omitted, none are excluded. takes precedence over . Initializes a new instance of the class. Renders the Form Collection from the HttpRequest and appends it to the specified . ASP.NET Request Headers Example usage of ${aspnet-request-headers} ${aspnet-request-headers:OutputFormat=Flat} ${aspnet-request-headers:OutputFormat=Json} ${aspnet-request-headers:OutputFormat=Json:HeaderNames=username} ${aspnet-request-headers:OutputFormat=Json:Exclude=access_token} Header names to be rendered. If null or empty array, all headers will be rendered. Gets or sets the keys to exclude from the output. If omitted, none are excluded. Initializes a new instance of the class. Renders the ASP.NET Headers appends it to the specified . The to append the rendered data to. Logging event. ASP.NET host. Use this layout renderer host. ${aspnet-request-host} Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Http Request Method. Example usage of ${aspnet-request-method}: ${aspnet-request-method} - Produces - Post. ASP.NET Http Request Method The to append the rendered data to. Logging event. Render the request IP for ASP.NET Core ${aspnet-request-ip} The header name to check for the Forwarded-For. Default "X-Forwarded-For". Needs Gets or sets whether the renderer should check value of header Render IP ASP.NET posted body, e.g. FORM or Ajax POST Example usage of ${aspnet-request-posted-body}: ${aspnet-request-posted-body} - Produces - {username:xyz,password:xyz} Max size in bytes of the body. Skip logging of the body when larger. Default 30720 Bytes = 30 KiB (0 = No limit, -1 = No Buffer Limit) Renders the ASP.NET posted body The to append the rendered data to. Logging event. Can seek now? ASP.NET Request Cookie Example usage of ${aspnet-request-querystring}: ${aspnet-request-querystring:OutputFormat=Flat} ${aspnet-request-querystring:OutputFormat=Json} List Query Strings' Key to be rendered from Request. If empty, then render all querystrings Renders the specified ASP.NET Application variable and appends it to the specified . ASP.NET Request Referrer Example usage of ${aspnet-request-referrer}: ${aspnet-request-referrer} - Produces - Referrer URL String from the Request. Renders the Referrer URL from the HttpRequest . The to append the rendered data to. Logging event. ASP.NET Request URL Example usage of ${aspnet-request-url}: ${aspnet-request-url:IncludeQueryString=true} - produces http://www.exmaple.com/?t=1 ${aspnet-request-url:IncludeQueryString=false} - produces http://www.exmaple.com/ ${aspnet-request-url:IncludePort=true} - produces http://www.exmaple.com:80/ ${aspnet-request-url:IncludePort=false} - produces http://www.exmaple.com/ ${aspnet-request-url:IncludeScheme=false} - produces www.exmaple.com/ ${aspnet-request-url:IncludePort=true:IncludeQueryString=true} - produces http://www.exmaple.com:80/?t=1 To specify whether to include / exclude the Query string. Default is false. To specify whether to include / exclude the Port. Default is false. To specify whether to exclude / include the host. Default is true. To specify whether to exclude / include the scheme. Default is true. Renders the Request URL from the HttpRequest The to append the rendered data to. Logging event. ASP.NET User Agent Example usage of ${aspnet-request-useragent}: ${aspnet-request-useragent} - Produces - User Agent String from the Request. Renders the ASP.NET User Agent The to append the rendered data to. Logging event. ASP.NET Request variable. Use this layout renderer to insert the value of the specified parameter of the ASP.NET Request object. Example usage of ${aspnet-request}: ${aspnet-request:item=v} ${aspnet-request:querystring=v} ${aspnet-request:form=v} ${aspnet-request:cookie=v} ${aspnet-request:header=h} ${aspnet-request:serverVariable=v} Gets or sets the item name. The QueryString, Form, Cookies, or ServerVariables collection variables having the specified name are rendered. Gets or sets the QueryString variable to be rendered. Gets or sets the form variable to be rendered. Gets or sets the cookie to be rendered. Gets or sets the ServerVariables item to be rendered. Gets or sets the Headers item to be rendered. Renders the specified ASP.NET Request variable and appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Response Status Code. Example usage of ${aspnet-response-statuscode}: ${aspnet-response-statuscode} - Produces - 200. ASP.NET Http Response Status Code The to append the rendered data to. Logging event. ASP.NET Session ID. Renders the ASP.NET Session ID appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Session variable. Use this layout renderer to insert the value of the specified variable stored in the ASP.NET Session dictionary. You can set the value of an ASP.NET Session variable by using the following code: Example usage of ${aspnet-session}: ${aspnet-session:variable=myvariable} - produces "123" ${aspnet-session:variable=anothervariable} - produces "01/01/2006 00:00:00" ${aspnet-session:variable=anothervariable:culture=pl-PL} - produces "2006-01-01 00:00:00" ${aspnet-session:variable=myvariable:padding=5} - produces " 123" ${aspnet-session:variable=myvariable:padding=-5} - produces "123 " ${aspnet-session:variable=stringvariable:upperCase=true} - produces "AAA BBB" Initializes a new instance of the class. Gets or sets the session variable name. Gets or sets whether variables with a dot are evaluated as properties or not Gets or sets the culture used for rendering. Renders the specified ASP.NET Session value and appends it to the specified . The to append the rendered data to. Logging event. ASP.NET Request TraceIdentifier. Ignore the System.Diagnostics.Activity.Current.Id value (AspNetCore3 uses ActivityId by default) Requires IIS ETW feature enabled. https://docs.microsoft.com/en-us/iis/configuration/system.webServer/httpTracing/ See also http://blog.tatham.oddie.com.au/2012/02/07/code-request-correlation-in-asp-net/ ASP.NET User variable. Renders the specified ASP.NET User.Identity.AuthenticationType variable and appends it to the specified . The to append the rendered data to. Logging event. ASP.NET User variable. Renders the specified ASP.NET User.Identity.Name variable and appends it to the specified . The to append the rendered data to. Logging event. Rendering WebRootPath. ("/") Append to target The to append the rendered data to. Logging event. Extend NLog.LayoutRenderers.AssemblyVersionLayoutRenderer with ASP.NET Full and Core support Rendering site name in IIS. Append to target The to append the rendered data to. Logging event. ASP.NET HttpModule that enables NLog to hook BeginRequest and EndRequest events easily. Event to be raised at the end of each HTTP Request. Event to be raised at the beginning of each HTTP Request. Initializes the HttpModule. ASP.NET application. Disposes the module. Writes log messages to the ASP.NET trace. Documentation on NLog Wiki Log entries can then be viewed by navigating to http://server/path/Trace.axd. Initializes a new instance of the class. The default value of the layout is: ${longdate}|${level:uppercase=true}|${logger}|${message} Writes the specified logging event to the ASP.NET Trace facility. If the log level is greater than or equal to it uses the System.Web.TraceContext.Warn method, otherwise it uses System.Web.TraceContext.Write method. The logging event. Buffers log events for the duration of ASP.NET request and sends them down to the wrapped target at the end of a request. Documentation on NLog Wiki

Typically this target is used in cooperation with PostFilteringTargetWrapper to provide verbose logging for failing requests and normal or no logging for successful requests. We need to make the decision of the final filtering rule to apply after all logs for a page have been generated.

To use this target, you need to add an entry in the httpModules section of web.config:

]]>

To set up the ASP.NET Buffering target wrapper configuration file, put the following in web.nlog file in your web application directory (this assumes that PostFilteringWrapper is used to provide the filtering and actual logs go to a file).

This assumes just one target and a single rule. More configuration options are described here.

To configure the target programmatically, put the following piece of code in your Application_OnStart() handler in Global.asax.cs or some other place that gets executed at the very beginning of your code:

Fully working C# project can be found in the Examples/Targets/Configuration API/ASPNetBufferingWrapper directory along with usage instructions.

Initializes a new instance of the class. Initializes a new instance of the class. The wrapped target. Initializes a new instance of the class. The wrapped target. Size of the buffer. Gets or sets the number of log events to be buffered. Gets or sets a value indicating whether buffer should grow as needed. A value of true if buffer should grow as needed; otherwise, false. Value of true causes the buffer to expand until is hit, false causes the buffer to never expand and lose the earliest entries in case of overflow. Gets or sets the maximum number of log events that the buffer can keep. Initializes the target by hooking up the NLogHttpModule BeginRequest and EndRequest events. Closes the target by flushing pending events in the buffer (if any). Adds the specified log event to the buffer. The log event. To control the Renderer Output formatting. Use this format for rendering the output value as a flat string. Use this format for rendering the output value as a json formatted string. Get value of a property key Container to perform value lookup using key function to get a value with this key evaluate as a nested property path. E.g. A.B is property B inside A. value Is the user authenticated? 0 = not authenticated, 1 = authenticated ${aspnet-user-isAuthenticated} Render 0 or 1