MessageBoxTarget Class |
Namespace: NLog.Windows.Forms
The MessageBoxTarget type exposes the following members.
| Name | Description | |
|---|---|---|
| MessageBoxTarget |
Initializes a new instance of the MessageBoxTarget class.
|
| Name | Description | |
|---|---|---|
| Caption |
Gets or sets the message box title.
| |
| 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" 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="msgbox" xsi:type="MessageBox" layout="${longdate}: ${message}" caption="${level}" /> 7 </targets> 8 9 <rules> 10 <logger name="*" minlevel="Debug" writeTo="msgbox" /> 11 </rules> 12</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:
1!ERROR: See log file!