Click or drag to resize

OutputDebugStringTarget Class

Outputs log messages through the OutputDebugString() Win32 API.
Inheritance Hierarchy
SystemObject
  NLog.TargetsTarget
    NLog.TargetsTargetWithLayout
      NLog.TargetsTargetWithLayoutHeaderAndFooter
        NLog.TargetsOutputDebugStringTarget

Namespace:  NLog.Targets
Assembly:  NLog.OutputDebugString (in NLog.OutputDebugString.dll) Version: 6.0.3+e276e1969a52b8ecc5cc84c1670a516efea0cb19
Syntax
public sealed class OutputDebugStringTarget : TargetWithLayoutHeaderAndFooter

The OutputDebugStringTarget type exposes the following members.

Constructors
  NameDescription
Public methodOutputDebugStringTarget
Initializes a new instance of the OutputDebugStringTarget class.
Public methodOutputDebugStringTarget(String)
Initializes a new instance of the OutputDebugStringTarget class.
Top
Properties
  NameDescription
Public propertyFooter
Gets or sets the footer.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Public propertyHeader
Gets or sets the header.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Public propertyLayout
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Public propertyName
Gets or sets the name of the target.
(Inherited from Target.)
Top
Methods
  NameDescription
Public methodDispose
Closes the target.
(Inherited from Target.)
Public methodFlush
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.)
Public methodPrecalculateVolatileLayouts
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.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Target.)
Public methodWriteAsyncLogEvent
Writes the log to the target.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(AsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(IListAsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Top
Remarks
Examples

To set up the target in the configuration file, use the following syntax:

XML
 1<?xml version="1.0" ?>
 2<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
 4
 5    <targets>
 6        <target name="n" xsi:type="OutputDebugString" layout="${message}" />
 7    </targets>
 8
 9    <rules>
10        <logger name="*" minlevel="Debug" writeTo="n" />
11    </rules>
12</nlog>

To set up the log target programmatically use code like this:

C#
 1using NLog;
 2using NLog.Config;
 3using NLog.Targets;
 4
 5class Example
 6{
 7    static void Main(string[] args)
 8    {
 9        OutputDebugStringTarget target = new OutputDebugStringTarget();
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    }
19}
See Also