/// <summary> /// Translates Syslog messages to Eventlog messages /// Using Pri part as source, and log them to Windows EventLog /// </summary> /// <param name="endPoint">IP/port number from datagram sender</param> /// <param name="strReceived">Syslog message</param> private void Log(EndPoint endPoint, string strReceived) { Pri pri = new Pri(m_regex.Match(strReceived).Groups[1].Value); EventLogEntryType eventLogEntryType = Severity2EventLogEntryType(pri.Severity); string strMessage = string.Format("{0} : {1}", endPoint, m_regex.Replace(strReceived, evaluator)); EventLog myLog = new EventLog(m_EventLog); myLog.Source = pri.ToString(); myLog.WriteEntry(strMessage, eventLogEntryType); myLog.Close(); myLog.Dispose(); }
/// <summary> /// Evaluator is being used to translate every decimal Pri header in /// a Syslog message to an 'Facility.Severity ' string. /// </summary> /// <param name="match">Any Pri header match in a message</param> /// <returns>Translated decimal Pri header to 'Facility.Severity '</returns> private string evaluator(Match match) { Pri pri = new Pri(match.Groups[1].Value); return pri.ToString()+" "; }
/// <summary> /// Creates a xml message based on the data in the object. It is used before the message is send to the server. /// </summary> protected virtual XmlDocument CreateXmlMessage() { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("NOTIFICATION"); if (NotificationTypeSpecified) { root.Attributes.Append(doc.CreateAttribute("ver")).Value = ((int)NotificationType).ToString(CultureInfo.InvariantCulture); } root.Attributes.Append(doc.CreateAttribute("id")).Value = Id.ToString(); if (siteId > 0) { root.Attributes.Append(doc.CreateAttribute("siteid")).Value = SiteId.ToString(); } if (siteUrl.Length > 0) { root.Attributes.Append(doc.CreateAttribute("siteurl")).Value = SiteUrl; } XmlElement to = doc.CreateElement("TO"); if (ReceiverMemberIdLow.Length > 0 && ReceiverMemberIdHigh.Length > 0) { to.Attributes.Append(doc.CreateAttribute("pid")).Value = ReceiverMemberIdLow.ToString() + ":" + ReceiverMemberIdHigh.ToString(); } if (ReceiverAccount.Length > 0) { to.Attributes.Append(doc.CreateAttribute("name")).Value = ReceiverAccount; } if (ReceiverOfflineMail.Length > 0) { to.Attributes.Append(doc.CreateAttribute("email")).Value = ReceiverOfflineMail; } if (SendDevice.Length > 0) { XmlElement via = doc.CreateElement("VIA"); via.Attributes.Append(doc.CreateAttribute("agent")).Value = SendDevice; to.AppendChild(via); } root.AppendChild(to); XmlElement from = doc.CreateElement("FROM"); if (SenderMemberIdLow.Length > 0 && SenderMemberIdHigh.Length > 0) { from.Attributes.Append(doc.CreateAttribute("pid")).Value = SenderMemberIdLow.ToString() + ":" + SenderMemberIdHigh.ToString(); } if (SenderAccount.Length > 0) { from.Attributes.Append(doc.CreateAttribute("name")).Value = SenderAccount; } root.AppendChild(from); XmlElement msg = doc.CreateElement("MSG"); if (Pri.Length > 0) { msg.Attributes.Append(doc.CreateAttribute("pri")).Value = Pri.ToString(); } msg.Attributes.Append(doc.CreateAttribute("id")).Value = MessageId.ToString(); if (ActionUrl.Length > 0) { XmlElement action = doc.CreateElement("ACTION"); action.Attributes.Append(doc.CreateAttribute("url")).Value = ActionUrl; msg.AppendChild(action); } if (SubcriptionUrl.Length > 0) { XmlElement subscr = doc.CreateElement("SUBSCR"); subscr.Attributes.Append(doc.CreateAttribute("url")).Value = SubcriptionUrl; msg.AppendChild(subscr); } if (CatId.Length > 0) { XmlElement cat = doc.CreateElement("CAT"); cat.Attributes.Append(doc.CreateAttribute("id")).Value = CatId.ToString(); msg.AppendChild(cat); } XmlElement body = doc.CreateElement("BODY"); if (Language.Length > 0) { body.Attributes.Append(doc.CreateAttribute("id")).Value = Language; } if (IconUrl.Length > 0) { body.Attributes.Append(doc.CreateAttribute("icon")).Value = IconUrl; } if (Text.Length > 0) { XmlElement textEl = doc.CreateElement("TEXT"); textEl.AppendChild(doc.CreateTextNode(Text)); body.AppendChild(textEl); } if (OfflineText.Length > 0) { XmlElement emailTextEl = doc.CreateElement("EMAILTEXT"); emailTextEl.AppendChild(doc.CreateTextNode(OfflineText)); body.AppendChild(emailTextEl); } msg.AppendChild(body); root.AppendChild(msg); doc.AppendChild(root); return(doc); }
/// <summary> /// Evaluator is being used to translate every decimal Pri header in /// a Syslog message to an 'Facility.Severity ' string. /// </summary> /// <param name="match">Any Pri header match in a message</param> /// <returns>Translated decimal Pri header to 'Facility.Severity '</returns> private string evaluator(Match match) { Pri pri = new Pri(match.Groups[1].Value); return(pri.ToString() + " "); }