MSMQ Target Writes log message to the specified message queue handled by MSMQ. | Assembly | Class | .NET Framework | .NET CF | Mono on Windows | Mono on Unix |
|---|
| 1.0 | 1.1 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 |
|---|
| NLog.dll | NLog.Win32.Targets.MSMQTarget |  |  |  |  |  | | | | |
Parameters (blue fields are required):| Name | Type | Description |
|---|
| layout | string
${} | | The text to be rendered. Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}. |
| | name | string | | | queue | string
${} | | Name of the queue to write to. To write to a private queue on a local machine use .\private$\QueueName. For other available queue names, consult MSMQ documentation. |
| | createQueueIfNotExists | boolean | | Create the queue if it doesn't exists. Default value is: False. |
| | encoding | string | | Encoding to be used when writing text to the queue. |
| | label | string
${} | | The label to associate with each message. Default value is: NLog. By default no label is associated. |
| | recoverable | boolean | | Use recoverable messages (with guaranteed delivery). Default value is: False. |
| | useXmlEncoding | boolean | | Use the XML format when serializing message. Default value is: False. |
|
Example: To set up the target in the configuration file, use the following syntax: <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="queue" xsi:type="MSMQ" layout="${message}"
queue=".\private$\nlog" encoding="iso-8859-2" recoverable="true"
label="${logger}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="queue"/>
</rules>
</nlog>
You can use a single target to write to multiple queues (similar to writing to multiple files with the File target). <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="queue" xsi:type="MSMQ" layout="${message}"
queue=".\private$\nlog.${logger}" encoding="iso-8859-2"
recoverable="true" label="${logger}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="queue"/>
</rules>
</nlog>
The above examples assume just one target and a single rule. More configuration options are described here. To set up the log target programmatically use code like this: using NLog;
using NLog.Config;
using NLog.Win32.Targets;
class Example
{
static void Main(string[] args)
{
NLog.Internal.InternalLogger.LogToConsole = true;
MSMQTarget target = new MSMQTarget();
target.Queue = ".\\private$\\nlog";
target.Label = "${message}";
target.Layout = "${message}";
target.CreateQueueIfNotExists = true;
target.Recoverable = true;
SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
Logger l = LogManager.GetLogger("AAA");
l.Error("This is an error. It goes to .\\private$\\nlog queue.");
l.Debug("This is a debug information. It goes to .\\private$\\nlog queue.");
l.Info("This is a information. It goes to .\\private$\\nlog queue.");
l.Warn("This is a warn information. It goes to .\\private$\\nlog queue.");
l.Fatal("This is a fatal information. It goes to .\\private$\\nlog queue.");
l.Trace("This is a trace information. It goes to .\\private$\\nlog queue.");
}
}
Back to the target list. |