TraceTarget Class |
Namespace: NLog.Targets
The TraceTarget type exposes the following members.
Name | Description | |
---|---|---|
TraceTarget |
Initializes a new instance of the TraceTarget class.
| |
TraceTarget(String) |
Initializes a new instance of the TraceTarget class.
|
Name | Description | |
---|---|---|
EnableTraceFail | ||
Footer |
Gets or sets the footer.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
Header |
Gets or sets the header.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
Layout |
Gets or sets the text to be rendered.
(Inherited from TargetWithLayoutHeaderAndFooter.) | |
Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
RawWrite |
Force use WriteLine(String) independent of LogLevel |
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="n" xsi:type="Trace" layout="${message}" /> 6 </targets> 7 8 <rules> 9 <logger name="*" minlevel="Debug" writeTo="n" /> 10 </rules> 11</nlog>
To set up the log target programmatically use code like this:
1using System; 2 3using NLog; 4using NLog.Targets; 5using System.Diagnostics; 6 7class Example 8{ 9 static void Main(string[] args) 10 { 11 Trace.Listeners.Add(new ConsoleTraceListener()); 12 13 TraceTarget target = new TraceTarget(); 14 target.Layout = "${message}"; 15 16 NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 17 18 Logger logger = LogManager.GetLogger("Example"); 19 logger.Debug("log message"); 20 } 21}