runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

 

--

发送:

GelfLogModel m = new GelfLogModel();
                m.version = "1.1";
                m.host = "128.0.14.99";
                m.short_message = "异常"; //三个字段必须
                m.full_message = "full_message ,测试1";
                m.timestamp = MU.GetTimeStampTen();

                string json = JsonConvert.SerializeObject(m);

                

                IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("128.0.255.99"), 12201);
                Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                byte[] data = Encoding.UTF8.GetBytes(json);
                server.SendTo(data, data.Length, SocketFlags.None, ipep);//将数据发送到指定的终结点

                MessageBox.Show("finish");

 

 

 

---

timestamp:

public static long GetTimeStampTen()
        {
            return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
        }

 

 实体类:

namespace WindowsFormsGrayLog
{
    public class GelfLogModel
    {

        /*
         version,host,short_message 这三项必填
         */

        public string version { get; set; }
        public string host { get; set; }

        public string short_message { get; set; }


        public string full_message { get; set; }
        public long timestamp { get; set; }


        #region 自定义字段

        public string mch_no { get; set; }
        public string out_trade_no { get; set; }

        #endregion
    }
}

 

---

posted on 2019-07-07 11:53  runliuv  阅读(394)  评论(0编辑  收藏  举报