Exemplo n.º 1
0
        private static DateTime?DateTimePartImpl(string line, LogLineDescriptor descriptor)
        {
            if (line.Length < descriptor.DatetimeIndexStart + descriptor.DatetimeLength)
            {
                return(null);
            }
            var possibleTimeStamp = line.Substring(descriptor.DatetimeIndexStart, descriptor.DatetimeLength);

            return(DateTime.TryParseExact(possibleTimeStamp, descriptor.DateTimeFormatString, CultureInfo.InvariantCulture,
                                          DateTimeStyles.None, out var t) ? t : (DateTime?)null);
        }
Exemplo n.º 2
0
        public DateTime?DateTimePart(string line)
        {
            if (m_logLineDescriptor == null)
            {
                // Evaluate the appropriate descriptor for the line
                foreach (var logLineDescriptor in m_logLineDescriptors)
                {
                    if (DateTimePartImpl(line, logLineDescriptor) != null)
                    {
                        m_logLineDescriptor = logLineDescriptor;
                        break;
                    }
                }
            }

            if (m_logLineDescriptor == null)
            {
                return(null);
            }

            return(DateTimePartImpl(line, m_logLineDescriptor));
        }