Sending log to remote MSMQ
I installed NLog version 2 and sending to a remote MSMQ is not working. Do I have the config setup properly?
<nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="MSMQ" name="MSMQLog" useXmlEncoding="true" queue="FormatName:DIRECT=OS:server01\private$\test_log" recoverable="true" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="MSMQLog" />
</rules>
</nlog>
I installed MSMQ on my local box and the server I'm sending the message too. NLog开发者_开发技巧 doesn't throw any exceptions (they are turned on). I don't see anything in the outgoing mailbox on my local machine.
I am able to send to the queue by using the following code.
using (var queue = new MessageQueue(@"FormatName:DIRECT=OS:server01\private$\tasi_log"))
{
var message = new Message("TEST");
message.Formatter = new BinaryMessageFormatter();
queue.Send(message);
}
Does NLog work with remote queues?
So I tried sending to a public queue and it still didn't work using NLog. So, I looked at the NLog.Extended source code and I found this method.
protected override void Write(LogEventInfo logEvent)
{
if (this.Queue == null)
{
return;
}
string queue = this.Queue.Render(logEvent);
if (!MessageQueue.Exists(queue))
{
if (this.CreateQueueIfNotExists)
{
MessageQueue.Create(queue);
}
else
{
return;
}
}
using (MessageQueue mq = new MessageQueue(queue))
{
Message msg = this.PrepareMessage(logEvent);
if (msg != null)
{
mq.Send(msg);
}
}
}
I commented out the following if statement and it now sends to remote queues. Can someone verify this? Is this a bug, or am I missing something?
if (!MessageQueue.Exists(queue))
{
if (this.CreateQueueIfNotExists)
{
MessageQueue.Create(queue);
}
else
{
return;
}
}
精彩评论