Beispiel #1
0
        /// <summary>
        /// Parses the specified line.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <returns>
        /// The parsed line.
        /// </returns>
        public static CCLogLine Parse(string line)
        {
            var firstBlock  = line.IndexOf('[');
            var secondBlock = line.IndexOf(']');

            if ((firstBlock < 0) || (secondBlock < 0))
            {
                // Cannot parse - just return the line
                return(new CCLogLine {
                    Message = line
                });
            }

            try
            {
                // Pull the line apart and parse everything
                var time          = line.Substring(0, firstBlock - 1);
                var identity      = line.Substring(firstBlock + 1, secondBlock - firstBlock - 1);
                var identityParts = identity.Split(':');
                var logLine       = new CCLogLine
                {
                    Thread  = identityParts[0].Trim(),
                    Level   = identityParts[1].Trim(),
                    Message = line.Substring(secondBlock + 1).Trim()
                };
                try
                {
                    var commaPos = time.IndexOf(',');
                    if (commaPos > 0)
                    {
                        time = time.Substring(0, commaPos);
                    }

                    logLine.EventTime = DateTime.Parse(time.Trim());
                }
                catch (FormatException)
                {
                    // Unable to parse the date/time :-|
                }

                return(logLine);
            }
            catch
            {
                // If all else fails just return the line
                return(new CCLogLine {
                    Message = line
                });
            }
        }
Beispiel #2
0
        /// <summary>
        /// Parses the specified line.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <returns>
        /// The parsed line.
        /// </returns>
        public static CCLogLine Parse(string line)
        {
            var firstBlock = line.IndexOf('[');
            var secondBlock = line.IndexOf(']');
            if ((firstBlock < 0) || (secondBlock < 0))
            {
                // Cannot parse - just return the line
                return new CCLogLine { Message = line };
            }

            try
            {
                // Pull the line apart and parse everything
                var time = line.Substring(0, firstBlock - 1);
                var identity = line.Substring(firstBlock + 1, secondBlock - firstBlock - 1);
                var identityParts = identity.Split(':');
                var logLine = new CCLogLine
                    {
                        Thread = identityParts[0].Trim(),
                        Level = identityParts[1].Trim(),
                        Message = line.Substring(secondBlock + 1).Trim()
                    };
                try
                {
                    var commaPos = time.IndexOf(',');
                    if (commaPos > 0)
                    {
                        time = time.Substring(0, commaPos);
                    }

                    logLine.EventTime = DateTime.Parse(time.Trim());
                }
                catch (FormatException)
                {
                    // Unable to parse the date/time :-|
                }

                return logLine;
            }
            catch
            {
                // If all else fails just return the line
                return new CCLogLine { Message = line };
            }
        }