Exemplo n.º 1
0
        private DateTime?ParseTimestamp(string line)
        {
            // If we stumble upon a file that doesn't contain a single timestamp in the first hundred log lines,
            // then we will just call it a day and never try again...
            // This obviously opens the possibility for not being able to detect valid timestamps in a file, however
            // this is outweighed by being able to read a file without memory FAST. The current algorithm to detect
            // the position and format is so slow that I can read about 1k lines of random data which is pretty bad...
            if (_numTimestampSuccess == 0 &&
                _numSuccessiveTimestampFailures >= 100)
            {
                return(null);
            }

            DateTime timestamp;

            if (_timestampParser.TryParse(line, out timestamp))
            {
                ++_numTimestampSuccess;
                _numSuccessiveTimestampFailures = 0;
                return(timestamp);
            }

            ++_numSuccessiveTimestampFailures;
            return(null);
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public bool TryParse(string content, out DateTime timestamp)
 {
     try
     {
         return(_parser.TryParse(content, out timestamp));
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Caught unexpected exception: {0}", e);
         timestamp = DateTime.MinValue;
         return(false);
     }
 }
Exemplo n.º 3
0
        private bool TryParseTimestamp(string content, out DateTime timestamp)
        {
            if (_determinedParser != null && DateTimeColumn != null && DateTimeLength != null)
            {
                var start  = DateTimeColumn.Value;
                var length = DateTimeLength.Value;
                if (content.Length >= start + length)
                {
                    var timestampValue = content.Substring(start, length);
                    if (_determinedParser.TryParse(timestampValue, out timestamp))
                    {
                        return(true);
                    }
                }
            }

            timestamp = DateTime.MinValue;
            return(false);
        }