private static string GetStructuredDataValue(string s) { s = SyslogUtil.EscpaeStructuredDataValue(s); s = ReplaceNewLines(s); return(s); }
private void SetPriorityValues(SyslogMessage msg, int priorityValue) { SyslogFacility facility; SyslogSeverity severity; SyslogUtil.GetPriValues(priorityValue, out facility, out severity); msg.Facility = facility; msg.Severity = severity; }
public string GetString(SyslogMessage msg) { StringBuilder sb = new StringBuilder(); var pri = SyslogUtil.CreatePri(msg.Facility, msg.Severity); var timestamp = msg.TimeStamp.ToString("MMM dd HH:mm:ss"); return(string.Format("<{0}>{1} {2} {3}", pri, timestamp.Trim(), HandleNulls(msg.HostName), msg.MessageText)); }
public string GetString(SyslogMessage msg) { int pri = SyslogUtil.CreatePri(msg.Facility, msg.Severity); string version = msg.Version; string structuredDataString = null; if (version == null || version.Trim() == "") { version = SyslogConstants.Version; } if (msg.StructuredData == null || msg.StructuredData.Count == 0) { structuredDataString = SyslogConstants.NilValue; } else { StringBuilder sb = new StringBuilder(); foreach (var sd in msg.StructuredData) { GetStructuredDataString(sd, sb); } structuredDataString = sb.ToString(); } return(string.Format("<{0}>{1} {2} {3} {4} {5} {6} {7} {8}", pri, version, Rfc3339DateFormat.GetString(msg.TimeStamp), ReplaceSpaces(HandleNulls(msg.HostName)), ReplaceSpaces(HandleNulls(msg.AppName)), ReplaceSpaces(HandleNulls(msg.ProcessID)), ReplaceSpaces(HandleNulls(msg.MessageID)), structuredDataString, msg.MessageText)); }
public IList <StructuredDataElement> ParseStructuredData(string sd) { List <StructuredDataElement> results = new List <StructuredDataElement>(); sd = sd.Trim(); StructuredDataElement current = null; //normalize structured data using (StringReader sr = new StringReader(sd)) { char c = (char)sr.Read(); //first char should be start of sd element if (c == '[') { current = new StructuredDataElement(); } else { throw new FormatException(); //not in format } current = new StructuredDataElement(); //we have the start of thing, read the name current.ID = sr.ReadUntilSpace(); while (sr.Peek() != -1) { //now read property names string key = sr.ReadUntilCharAndThenConsume('='); //next char should be quote if (sr.Read() != '"') { throw new FormatException(); //not in format } //now read the value string value = sr.ReadUntilCharAndThenConsume('"'); //if value ends in escpae char, then while (value.EndsWith("\\")) { string addition = "\"" + sr.ReadUntilCharAndThenConsume('"'); value += addition; } value = SyslogUtil.UnescapeStructuredDataValue(value); current.Properties.Add(key, value); //end of key/value pair, read another one sr.MaybeConsumeSpaces(); if (sr.Peek() == ']') //check to see if we are end of sd { sr.Read(); results.Add(current); current = null; } if (sr.Peek() == '[') //check to see if we are new start { //consume start char sr.Read(); current = new StructuredDataElement(); //we have the start of thing, read the name string name = sr.ReadUntilSpace(); current.ID = name; } } } return(results); }