ASPNetTrace Target Writes logging messages to the ASP.NET trace. | Assembly | Class | .NET Framework | .NET CF | Mono on Windows | Mono on Unix |
|---|
| 1.0 | 1.1 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 |
|---|
| NLog.dll | NLog.Targets.ASPNetTraceTarget |  |  |  | | |  |  |  |  |
Parameters (blue fields are required):| Name | Type | Description |
|---|
| layout | string
${} | | The text to be rendered. Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}. |
| | name | string | |
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. |