using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
using System.Configuration;

namespace CommonEntity
{
    public class LogRecorrd
    {
        private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(LogRecorrd));
        public static readonly string LogReportUrl = ConfigurationManager.AppSettings["debug_log_report_url"];
        public static void WebAPI_DataSend<T>(T t, string topic)
        {
            try
            {
                //这个是 定阅的服务器要写的
                //string debug_log_report_mqtt_topic = "blw/webapi/monitor/";
                string str = Newtonsoft.Json.JsonConvert.SerializeObject(t);
                var client1 = new RestClient(LogReportUrl);
                var request1 = new RestRequest("/", Method.POST);

                //注意方法是POST
                //两个参数名字必须是 topic 和payload ，区分大小写的
                request1.AddParameter("topic", topic);
                request1.AddParameter("payload", str);


                client1.ExecuteAsync(request1, (response) => { });
            }
            catch (Exception ex)
            {
                logger.Error("SendMQTTData: " + ex.Message);
            }
        }
    }
}
