Есть ли способ программно включить ведение журнала на локальный жесткий диск?
(например: запись в файл C: \ temp \ Rabbit.log)
((конечно, каталог и имя изменятся))
Другими словами, я хочу иметь возможность включать (или выключать) вход в систему при создании соединения Rabbit MQ ...
Справочная информация:
RabbitMQ используется по ссылке в моем приложении
В Visual Studio щелкните правой кнопкой мыши «Ссылки» через NuGet
add reference : RabbitMQ.Client.dll (v4.0.30319)
Вот мой код, который запускает клиентскую часть Rabbit MQ.
(код обработки сообщения удален)
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using RabbitMQ.Client.MessagePatterns;
private void Internal_Run(CancellationToken cancelToken)
{
var connectionFactory = new ConnectionFactory();
// I know this is wrong... but this is what I would ***like*** to do:
// connectionFactory.IsLogging = true;
// connectionFactory.LogPathAndFile = "C:\\Temp\\Rabbit.log";
connectionFactory.HostName = "My Host";
connectionFactory.UserName = "My userName";
connectionFactory.Password = "My password";
string QueueName = "My unique queue name";
try
{
using (IConnection connection = connectionFactory.CreateConnection())
{
using (IModel model = connection.CreateModel())
{
//Note declare the queue here, as well. Because we might start the receiver before the sender,
// we want to make sure the queue exists before we try to consume messages from it
model.QueueDeclare(queue: QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null);
var subscription = new Subscription(model, QueueName, false);
int milisecondTimeOut_RabbitMQ = 500;
while (true)
{
BasicDeliverEventArgs basicDeliveryEventArgs;
if (subscription.Next(milisecondTimeOut_RabbitMQ, out basicDeliveryEventArgs))
{
if (basicDeliveryEventArgs == null)
{
continue;
}
if (basicDeliveryEventArgs.Body.Length == 0)
{
continue;
}
string messageContent = Encoding.UTF8.GetString(basicDeliveryEventArgs.Body);
subscription.Ack(basicDeliveryEventArgs); // send the ACK back to queue to let Rabbit know I processed the message
}
if (cancelToken.IsCancellationRequested)
{
break;
}
}
}
}
}
catch (OperationCanceledException oce)
{
// this is an expected cancellation - program shutting down
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}