编程语言
首页 > 编程语言> > C# .NET UDP 形式调用 graylog,gelf

C# .NET UDP 形式调用 graylog,gelf

作者:互联网

 

 

--

发送:

GelfLogModel m = new GelfLogModel();
                m.version = "1.1";
                m.host = "128.0.14.39";
                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.10"), 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;
        }

 

 

---

标签:UDP,C#,server,128.0,graylog,GetTimeStampTen,new,message,data
来源: https://www.cnblogs.com/runliuv/p/11145864.html