/// <summary>
        /// Internal instance logging of a message
        /// </summary>
        private void LogInternal(Facility facility, Severity severity, string msg)
        {
            // Early out if the client's logging level is lower than the log message
            if (string.IsNullOrEmpty(msg) || severity > m_settings.minimumLoggingLevel || m_udpClient == null)
            {
                return;
            }
            // Calculate the message severity (facility * 8 + severity)
            int    severityValue = ((int)facility) * 8 + (int)severity;
            string message       = string.Empty;

            // Build the syslog message format
            lock (m_stringBuilder)
            {
                // Reset the string builder
                m_stringBuilder.Length = 0;
                // Severity
                m_stringBuilder.Append('<');
                m_stringBuilder.Append(severityValue);
                m_stringBuilder.Append('>');
                // Version 1
                m_stringBuilder.Append('1');
                m_stringBuilder.Append(' ');
                // Date time stamp in RFC3339 format
                m_stringBuilder.Append(Rfc3339DateTime.ToString(DateTime.UtcNow));
                m_stringBuilder.Append(' ');
                // The application that is logging
                string systemName = m_settings.systemName;
                if (string.IsNullOrEmpty(systemName))
                {
                    systemName = "unity-client";
                }
                m_stringBuilder.Append(systemName);
                m_stringBuilder.Append(' ');
                // Process name that is logging
                m_stringBuilder.Append(m_processName);
                m_stringBuilder.Append(' ');
                // Platform the client is running on
                m_stringBuilder.Append(m_platform);
                m_stringBuilder.Append(' ');
                // The log message with the client IP
                if (m_settings.logClientIPAdress)
                {
                    m_stringBuilder.Append(string.Format(s_ipPrefixFormat, m_localIp, msg));
                }
                else
                {
                    m_stringBuilder.Append(msg);
                }
                message = m_stringBuilder.ToString();
            }
            // Send the completed message
            BeginSend(message);
        }
Пример #2
0
        /// <summary>
        /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent.
        /// </summary>
        /// <param name="s">A string containing a date and time to convert.</param>
        /// <returns>A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>.</returns>
        /// <remarks>
        /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 3339 string representation of a date and time.</exception>
        public static DateTime Parse(string s)
        {
            //------------------------------------------------------------
            //  Validate parameter
            //------------------------------------------------------------
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }

            DateTime result;

            if (Rfc3339DateTime.TryParse(s, out result))
            {
                return(result);
            }
            else
            {
                throw new FormatException(String.Format(null, "{0} is not a valid RFC 3339 string representation of a date and time.", s));
            }
        }