PerfCounter Target Increments specified performance counter on each write. | 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.Win32.Targets.PerfCounterTarget |  |  |  | | | | | | |
Remarks: TODO: 1. Unable to create a category allowing multiple counter instances (.Net 2.0 API only, probably) 2. Is there any way of adding new counters without deleting the whole category? 3. There should be some mechanism of resetting the counter (e.g every day starts from 0), or auto-switching to another counter instance (with dynamic creation of new instance). This could be done with layouts. Parameters (blue fields are required):| Name | Type | Description |
|---|
| categoryName | string | | Performance counter category. |
| | counterName | string | | Name of the performance counter. |
| | name | string | | | autoCreate | boolean | | Whether performance counter should be automatically created. |
| | counterType | PerformanceCounterType | | Performance counter type. |
| | instanceName | string | |
Example: To set up the target in the configuration file, use the following syntax: <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="pc" xsi:type="PerfCounter" categoryName="My category"
counterName="My counter" counterType="NumberOfItems32"
instanceName="myInstance"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="pc"/>
</rules>
</nlog>
This assumes just one target and a single rule. More configuration options are described here. To set up the log target programmatically use code like this: using System;
using NLog;
using NLog.Targets;
using NLog.Win32.Targets;
using System.Diagnostics;
class Example
{
static void Main(string[] args)
{
PerfCounterTarget target = new PerfCounterTarget();
target.AutoCreate = true;
target.CategoryName = "My category";
target.CounterName = "My counter";
target.CounterType = PerformanceCounterType.NumberOfItems32;
target.InstanceName = "My instance";
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
Logger logger = LogManager.GetLogger("Example");
logger.Debug("log message");
}
}
Back to the target list. |