Last updated: 2006-09-18

This website is based on NLog v1.0. Click here to view the documentation for other versions.

ASPNetTrace Target


Writes logging messages to the ASP.NET trace.

AssemblyClass.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
NLog.dllNLog.Targets.ASPNetTraceTarget  

Parameters (blue fields are required):

NameTypeDescription
layoutstring  ${}
The text to be rendered.

Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}.

namestring
The name of the target.

Example:

To set up the ASP.NET Trace target in the configuration file, put the following in web.nlog file in your web application directory.

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
  <targets> 
    <target name="aspnet" xsi:type="ASPNetTrace" layout="${logger} ${message}"/> 
  </targets> 
  <rules> 
    <logger name="*" minlevel="Debug" writeTo="aspnet"/> 
  </rules> 
</nlog> 

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:

using System; 
using System.Web; 
 
using NLog; 
using NLog.Targets; 
 
namespace SomeWebApplication 
{ 
    public class Global : System.Web.HttpApplication 
    { 
        // 
        // this event handler is executed at the very start of the web application 
        // so this is a good place to configure targets programmatically 
        //  
        // alternative you could place this code in a static type constructor 
        // 
        protected void Application_Start(Object sender, EventArgs e) 
        { 
            ASPNetTraceTarget target = new ASPNetTraceTarget(); 
            target.Layout = "${logger} ${message}"; 
 
            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 
        } 
    } 
}

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

Resulting log entries can be viewed by navigating to http://server/path/Trace.axd.

HTTP Request List:

HTTP Request Details:


Back to the target list.
Webwww.nlog-project.org