![]() | DebugTarget Class |
Namespace: NLog.Targets
The DebugTarget type exposes the following members.
Name | Description | |
---|---|---|
![]() | DebugTarget |
Initializes a new instance of the DebugTarget class.
|
![]() | DebugTarget(String) |
Initializes a new instance of the DebugTarget class.
|
Name | Description | |
---|---|---|
![]() | Counter |
Gets the number of times this target has been called.
|
![]() | LastMessage |
Gets the last message rendered by this target.
|
![]() | Layout |
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayout.) |
![]() | Name |
Gets or sets the name of the target.
(Inherited from Target.) |
Name | Description | |
---|---|---|
![]() | Dispose |
Closes the target.
(Inherited from Target.) |
![]() | Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) |
![]() | 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.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Target.) |
![]() | 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.) |
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="debug" xsi:type="Debug" layout="${message}" /> 6 </targets> 7 8 <rules> 9 <logger name="*" minlevel="Info" writeTo="debug" /> 10 </rules> 11</nlog>
To set up the log target programmatically use code like this:
1using NLog; 2using NLog.Config; 3using NLog.Targets; 4 5class Example 6{ 7 static void Main(string[] args) 8 { 9 DebugTarget target = new DebugTarget(); 10 target.Layout = "${message}"; 11 12 LoggingConfiguration nlogConfig = new LoggingConfiguration(); 13 nlogConfig.AddRuleForAllLevels(target); 14 LogManager.Configuration = nlogConfig; 15 16 Logger logger = LogManager.GetLogger("Example"); 17 logger.Debug("log message"); 18 logger.Debug("another log message"); 19 20 Console.WriteLine("The debug target has been hit {0} times.", target.Counter); 21 Console.WriteLine("The last message was '{0}'.", target.LastMessage); 22 } 23}