public SyslogMessage(string hostName, string msg) { ValidateHost(hostName); ValidateMessage(msg); _messageTime = DateTime.UtcNow; _facility = DefaultFacility; _severity = DefaultSeverity; _localTime = DateTime.Now; _localHost = hostName; _message = msg; }
public SyslogMessage(string hostName, string msg, FacilityCode fc, SeverityCode sc, DateTime localTime) { ValidateHost(hostName); ValidateMessage(msg); _messageTime = DateTime.UtcNow; _facility = fc; _severity = sc; _localTime = localTime; _localHost = hostName; _message = msg; }
/// <summary> /// Creates a new instance of the SyslogMessage class. /// </summary> /// <param name="priority">Specifies the encoded PRI field, containing the facility and severity values.</param> /// <param name="timestamp">Specifies the timestamp, if present in the packet.</param> /// <param name="hostname">Specifies the hostname, if present in the packet. The hostname can only be present if the timestamp is also present (RFC3164).</param> /// <param name="message">Specifies the textual content of the message.</param> public SyslogMessage(int priority, DateTime timestamp, string hostname, string message) { if (priority > 0) { // The facility code is the nearest whole number of the priority value divided by 8 _facility = (FacilityCode)(int)Math.Floor((double)priority / 8); // The severity code is the remainder of the priority value divided by 8 _severity = (SeverityCode) (priority % 8); } else { _facility = FacilityCode.None; _severity = SeverityCode.None; } _timestamp = timestamp; _hostname = hostname; _message = message; }
private static void ParseCode(string code, out FacilityCode fc, out SeverityCode sc) { int numericCode = Convert.ToInt32(code); int facilityCode = numericCode / 8; int severityCode = numericCode % 8; if (!Enum.IsDefined(typeof(FacilityCode), facilityCode)) { throw new ArgumentException(String.Format("Invalid facility code {0}", facilityCode), "code"); } fc = (FacilityCode)facilityCode; if (!Enum.IsDefined(typeof(SeverityCode), severityCode)) { throw new ArgumentException(String.Format("Invalid severity code {0}", severityCode), "code"); } sc = (SeverityCode)severityCode; }
private static void ParseCode(string code, out FacilityCode fc, out SeverityCode sc) { int numericCode = Convert.ToInt32(code); int facilityCode = numericCode / 8; int severityCode = numericCode % 8; if (!Enum.IsDefined(typeof(FacilityCode), facilityCode)) throw new ArgumentException(String.Format("Invalid facility code {0}", facilityCode), "code"); fc = (FacilityCode) facilityCode; if (!Enum.IsDefined(typeof(SeverityCode), severityCode)) throw new ArgumentException(String.Format("Invalid severity code {0}", severityCode), "code"); sc = (SeverityCode) severityCode; }