You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using DSWeb.Common.DB;
|
|
using log4net;
|
|
using Newtonsoft.Json;
|
|
using RabbitMQ.Client;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DSWeb.Job.Common
|
|
{
|
|
public static class ActionLogHelper
|
|
{
|
|
private const string MqActionExchangeName = "djy.action";
|
|
private const string MqActionQueueName = "djy.action";
|
|
private static ILog logger = LogManager.GetLogger("ActionLogHelper");
|
|
|
|
public static void SendActionLog(DjyActionLog mqSendObj)
|
|
{
|
|
#region 记录动作
|
|
var strSendObj = JsonConvert.SerializeObject(mqSendObj);
|
|
try
|
|
{
|
|
ConnectionFactory factory = new ConnectionFactory();
|
|
factory.Uri = new Uri(ConfigurationManager.AppSettings["ActionLogMQUri"]);
|
|
using (IConnection conn = factory.CreateConnection())
|
|
{
|
|
IModel mqModel = conn.CreateModel();
|
|
mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct);
|
|
mqModel.QueueDeclare(MqActionQueueName, false, false, false, null);
|
|
mqModel.QueueBind(MqActionQueueName, MqActionExchangeName, MqActionQueueName, null);
|
|
byte[] messageBodyBytes = Encoding.UTF8.GetBytes(strSendObj);
|
|
IBasicProperties props = mqModel.CreateBasicProperties();
|
|
props.DeliveryMode = 2;
|
|
mqModel.BasicPublish(MqActionExchangeName,
|
|
MqActionQueueName, props,
|
|
messageBodyBytes);
|
|
conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error($"发送动作日志出错,参数对象:{strSendObj}");
|
|
logger.Error(ex.Message);
|
|
logger.Error(ex.StackTrace);
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
}
|