MessageQueueTarget Class |
Namespace: NLog.Targets
The MessageQueueTarget type exposes the following members.
Name | Description | |
---|---|---|
MessageQueueTarget |
Initializes a new instance of the MessageQueueTarget class.
| |
MessageQueueTarget(String) |
Initializes a new instance of the MessageQueueTarget class.
|
Name | Description | |
---|---|---|
CheckIfQueueExists |
Gets or sets a value indicating whether to check if a queue exists before writing to it.
| |
CreateQueueIfNotExists |
Gets or sets a value indicating whether to create the queue if it doesn't exists.
| |
Encoding |
Gets or sets the encoding to be used when writing text to the queue.
| |
IsInitialized |
Gets a value indicating whether the target has been initialized.
(Inherited from Target.) | |
Label |
Gets or sets the label to associate with each message.
| |
Layout |
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayout.) | |
LoggingConfiguration |
Gets the logging configuration this target is part of.
(Inherited from Target.) | |
Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
Queue |
Gets or sets the name of the queue to write to.
| |
Recoverable |
Gets or sets a value indicating whether to use recoverable messages (with guaranteed delivery).
| |
SingleTransaction |
Gets or sets a value indicating whether sending to a transactional queue using single-transaction-style.
| |
SyncRoot |
Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target.) | |
UseXmlEncoding |
Gets or sets a value indicating whether to use the XML format when serializing message.
|
Name | Description | |
---|---|---|
CloseTarget |
Closes the target to release any initialized resources
(Inherited from Target.) | |
Dispose |
Closes the target.
(Inherited from Target.) | |
Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources.
(Inherited from Target.) | |
Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) | |
FlushAsync |
Flush any pending log messages
(Inherited from Target.) | |
InitializeTarget |
Initializes the target before writing starts
(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.) | |
PrepareMessage |
Prepares a message to be sent to the message queue.
| |
RenderLogEvent(Layout, LogEventInfo) |
Renders the logevent into a string-result using the provided layout
(Inherited from Target.) | |
RenderLogEventT(LayoutT, LogEventInfo, T) |
Renders the logevent into a result-value by using the provided layout
(Inherited from Target.) | |
ResolveServiceT |
Resolve from DI ServiceRepository (Inherited from Target.) | |
ToString | Returns a string that represents the current object. (Inherited from Target.) | |
Write(AsyncLogEventInfo) |
Writes async log event to the log target.
(Inherited from Target.) | |
Write(IListAsyncLogEventInfo) |
Writes an array of logging events to the log target. By default it iterates on all
events and passes them to "Write" method. Inheriting classes can use this method to
optimize batch writes.
(Inherited from Target.) | |
Write(LogEventInfo) |
Writes the specified logging event to a queue specified in the Queue
parameter.
(Overrides TargetWrite(LogEventInfo).) | |
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.) | |
WriteAsyncThreadSafe(AsyncLogEventInfo) |
Writes a log event to the log target, in a thread safe manner.
Any override of this method has to provide their own synchronization mechanism.
!WARNING! Custom targets should only override this method if able to provide their
own synchronization mechanism. Layout-objects are not guaranteed to be
thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.) | |
WriteAsyncThreadSafe(IListAsyncLogEventInfo) |
Writes an array of logging events to the log target, in a thread safe manner.
Any override of this method has to provide their own synchronization mechanism.
!WARNING! Custom targets should only override this method if able to provide their
own synchronization mechanism. Layout-objects are not guaranteed to be
thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.) | |
WriteFailedNotInitialized |
LogEvent is written to target, but target failed to successfully initialize
(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 5 <targets> 6 <target name="queue" xsi:type="MSMQ" 7 layout="${message}" 8 queue=".\private$\nlog" 9 encoding="iso-8859-2" 10 recoverable="true" 11 label="${logger}" /> 12 </targets> 13 14 <rules> 15 <logger name="*" minlevel="Debug" writeTo="queue" /> 16 </rules> 17</nlog>
You can use a single target to write to multiple queues (similar to writing to multiple files with the File target).
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 5 <targets> 6 <target name="queue" xsi:type="MSMQ" 7 layout="${message}" 8 queue=".\private$\nlog.${logger}" 9 encoding="iso-8859-2" 10 recoverable="true" 11 label="${logger}" /> 12 </targets> 13 14 <rules> 15 <logger name="*" minlevel="Debug" writeTo="queue" /> 16 </rules> 17</nlog>
To set up the log target programmatically use code like this:
1using NLog; 2using NLog.Config; 3using NLog.Win32.Targets; 4 5class Example 6{ 7 static void Main(string[] args) 8 { 9 NLog.Internal.InternalLogger.LogToConsole = true; 10 11 MSMQTarget target = new MSMQTarget(); 12 target.Queue = ".\\private$\\nlog"; 13 target.Label = "${message}"; 14 target.Layout = "${message}"; 15 target.CreateQueueIfNotExists = true; 16 target.Recoverable = true; 17 18 SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace); 19 20 Logger l = LogManager.GetLogger("AAA"); 21 l.Error("This is an error. It goes to .\\private$\\nlog queue."); 22 l.Debug("This is a debug information. It goes to .\\private$\\nlog queue."); 23 l.Info("This is a information. It goes to .\\private$\\nlog queue."); 24 l.Warn("This is a warn information. It goes to .\\private$\\nlog queue."); 25 l.Fatal("This is a fatal information. It goes to .\\private$\\nlog queue."); 26 l.Trace("This is a trace information. It goes to .\\private$\\nlog queue."); 27 } 28}