Example #1
0
        public void SendMessage(MessageStruct Message, string RemoteHost)
        {
            UdpClient sendSocket = new UdpClient(RemoteHost, this.Port);

            byte[] output = System.Text.ASCIIEncoding.ASCII.GetBytes(
                string.Format("<{0}>{1} {2} {3} {4} {5} {6} {7} {8}",
                              ((int)Message.Pri.Facility * 8) + (int)Message.Pri.Severity,
                              1,                                                  //1
                              Message.TimeStamp.ToString("yyyy-MM-ddThh:mm:ssZ"), //2
                              System.Environment.MachineName,                     //3
                              Message.AppName,                                    //4
                              Message.ProcID,                                     //5
                              Message.MsgID,                                      //6
                              Message.GetStructuredDataString(),                  //7
                              Message.Message));                                  //8

            //MAKE SURE THE FINAL BUFFER IS LESS THEN 1024 BYTES AND IF SO THEN SEND THE DATA
            if (output.Length < 1024)
            {
                sendSocket.Send(output, output.Length);
                sendSocket.Close();
            }
            else
            {
                throw new InsufficientMemoryException("The data in which you are trying to send does not comply to syslog standards.\nThe total message size must be less then 1024 bytes.");
            }
        }