PerformanceCounterTarget Class |
Namespace: NLog.Targets
The PerformanceCounterTarget type exposes the following members.
Name | Description | |
---|---|---|
PerformanceCounterTarget |
Initializes a new instance of the PerformanceCounterTarget class.
| |
PerformanceCounterTarget(String) |
Initializes a new instance of the PerformanceCounterTarget class.
|
Name | Description | |
---|---|---|
AutoCreate |
Gets or sets a value indicating whether performance counter should be automatically created.
| |
CategoryName |
Gets or sets the name of the performance counter category.
| |
CounterHelp |
Gets or sets the counter help text.
| |
CounterName |
Gets or sets the name of the performance counter.
| |
CounterType |
Gets or sets the performance counter type.
| |
IncrementValue |
The value by which to increment the counter.
| |
InstanceName |
Gets or sets the performance counter instance name.
| |
IsInitialized |
Gets a value indicating whether the target has been initialized.
(Inherited from Target.) | |
LoggingConfiguration |
Gets the logging configuration this target is part of.
(Inherited from Target.) | |
Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
SyncRoot |
Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target.) |
Name | Description | |
---|---|---|
CloseTarget |
Closes the target to release any initialized resources
(Overrides TargetCloseTarget.) | |
Dispose |
Closes the target.
(Inherited from Target.) | |
Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources.
(Inherited from Target.) | |
Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) | |
FlushAsync |
Flush any pending log messages
(Inherited from Target.) | |
InitializeTarget |
Initializes the target before writing starts
(Inherited from Target.) | |
Install |
Performs installation which requires administrative permissions.
| |
IsInstalled |
Determines whether the item is installed.
| |
PrecalculateVolatileLayouts |
Calls the Precalculate(LogEventInfo) on each volatile layout
used by this target.
This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.) | |
RenderLogEvent(Layout, LogEventInfo) |
Renders the logevent into a string-result using the provided layout
(Inherited from Target.) | |
RenderLogEventT(LayoutT, LogEventInfo, T) |
Renders the logevent into a result-value by using the provided layout
(Inherited from Target.) | |
ResolveServiceT |
Resolve from DI ServiceRepository (Inherited from Target.) | |
ToString | Returns a string that represents the current object. (Inherited from Target.) | |
Uninstall |
Performs uninstallation which requires administrative permissions.
| |
Write(AsyncLogEventInfo) |
Writes async log event to the log target.
(Inherited from Target.) | |
Write(IListAsyncLogEventInfo) |
Writes an array of logging events to the log target. By default it iterates on all
events and passes them to "Write" method. Inheriting classes can use this method to
optimize batch writes.
(Inherited from Target.) | |
Write(LogEventInfo) |
Increments the configured performance counter.
(Overrides TargetWrite(LogEventInfo).) | |
WriteAsyncLogEvent |
Writes the log to the target.
(Inherited from Target.) | |
WriteAsyncLogEvents(AsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
WriteAsyncLogEvents(IListAsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
WriteAsyncThreadSafe(AsyncLogEventInfo) |
Writes a log event to the log target, in a thread safe manner.
Any override of this method has to provide their own synchronization mechanism.
!WARNING! Custom targets should only override this method if able to provide their
own synchronization mechanism. Layout-objects are not guaranteed to be
thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.) | |
WriteAsyncThreadSafe(IListAsyncLogEventInfo) |
Writes an array of logging events to the log target, in a thread safe manner.
Any override of this method has to provide their own synchronization mechanism.
!WARNING! Custom targets should only override this method if able to provide their
own synchronization mechanism. Layout-objects are not guaranteed to be
thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.) | |
WriteFailedNotInitialized |
LogEvent is written to target, but target failed to successfully initialize
(Inherited from Target.) |
To set up the target in the configuration file, use the following syntax:
1<?xml version="1.0" ?> 2<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4 <targets> 5 <target name="pc" xsi:type="PerfCounter" categoryName="My category" 6 counterName="My counter" counterType="NumberOfItems32" instanceName="myInstance" /> 7 </targets> 8 9 <rules> 10 <logger name="*" minlevel="Debug" writeTo="pc" /> 11 </rules> 12</nlog>
To set up the log target programmatically use code like this:
1using System; 2 3using NLog; 4using NLog.Targets; 5using NLog.Win32.Targets; 6using System.Diagnostics; 7 8class Example 9{ 10 static void Main(string[] args) 11 { 12 PerfCounterTarget target = new PerfCounterTarget(); 13 target.AutoCreate = true; 14 target.CategoryName = "My category"; 15 target.CounterName = "My counter"; 16 target.CounterType = PerformanceCounterType.NumberOfItems32; 17 target.InstanceName = "My instance"; 18 19 NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 20 21 Logger logger = LogManager.GetLogger("Example"); 22 logger.Debug("log message"); 23 } 24}