[This is preliminary documentation and is subject to change.]
Pops up logging messages as message boxes.
Namespace:
NLog.TargetsAssembly: NLog (in NLog.dll) Version: 2.0.0.0
Syntax
| C# |
|---|
public sealed class MessageBoxTarget : TargetWithLayout |
| Visual Basic (Declaration) |
|---|
Public NotInheritable Class MessageBoxTarget _ Inherits TargetWithLayout |
| Visual C++ |
|---|
public ref class MessageBoxTarget sealed : public TargetWithLayout |
Examples
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="msgbox" xsi:type="MessageBox" layout="${longdate}: ${message}" caption="${level}" /> 6 </targets> 7 8 <rules> 9 <logger name="*" minlevel="Debug" writeTo="msgbox" /> 10 </rules> 11</nlog>
This assumes just one target and a single rule. More configuration options are described here.
The result is a message box:
To set up the log target programmatically use code like this:
1using System; 2 3using NLog; 4using NLog.Targets; 5 6class Example 7{ 8 static void Main(string[] args) 9 { 10 MessageBoxTarget target = new MessageBoxTarget(); 11 target.Layout = "${longdate}: ${message}"; 12 target.Caption = "${level} message"; 13 14 NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 15 16 Logger logger = LogManager.GetLogger("Example"); 17 logger.Debug("log message"); 18 } 19}
Inheritance Hierarchy
System..::.Object
NLog.Targets..::.Target
NLog.Targets..::.TargetWithLayout
NLog.Targets..::.MessageBoxTarget
NLog.Targets..::.Target
NLog.Targets..::.TargetWithLayout
NLog.Targets..::.MessageBoxTarget
