NLog.Extended 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" Renders the specified ASP.NET Application variable and appends it to the specified . The to append the rendered data to. Logging event. Gets or sets the variable name. 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:serverVariable=v} Renders the specified ASP.NET Request variable and appends it to the specified . The to append the rendered data to. Logging event. 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. 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" Renders the specified ASP.NET Session value and appends it to the specified . The to append the rendered data to. Logging event. Gets or sets the session variable name. 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. 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. Writes the specified logging event to the ASP.NET Trace facility. If the log level is greater than or equal to it uses the method, otherwise it uses method. The logging event. Writes log message to the specified message queue handled by MSMQ. Documentation on NLog Wiki

To set up the target in the configuration file, use the following syntax:

You can use a single target to write to multiple queues (similar to writing to multiple files with the File target).

The above examples assume just one target and a single rule. More configuration options are described here.

To set up the log target programmatically use code like this:

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 a queue specified in the Queue parameter. The logging event. Prepares a message to be sent to the message queue. The log event to be used when calculating label and text to be written. The message to be sent. You may override this method in inheriting classes to provide services like encryption or message authentication. Gets or sets the name of the queue to write to. To write to a private queue on a local machine use .\private$\QueueName. For other available queue names, consult MSMQ documentation. Gets or sets the label to associate with each message. By default no label is associated. Gets or sets a value indicating whether to create the queue if it doesn't exists. Gets or sets a value indicating whether to use recoverable messages (with guaranteed delivery). Gets or sets the encoding to be used when writing text to the queue. Gets or sets a value indicating whether to use the XML format when serializing message. 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. 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. 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. ASP.NET HttpModule that enables NLog to hook BeginRequest and EndRequest events easily. Initializes the HttpModule. ASP.NET application. Disposes the module. Event to be raised at the end of each HTTP Request. Event to be raised at the beginning of each HTTP Request.