private IEnumerable <LogRow> TryGetLogs(OrderBy orderby) { var ci = CultureInfo.InvariantCulture; var encoding = Encoding.GetEncoding(_querylog.Encoding); using (var file = File.Open(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var reader = new StreamReader(file, encoding)) using (var csv = new CsvReader(reader, ci)) { csv.Configure(_querylog); var records = csv.GetRecords <LogRow>(); switch (orderby) { case OrderBy.Asc: return(records.OrderBy(e => e.Time).ToList()); case OrderBy.Desc: return(records.OrderByDescending(e => e.Time).ToList()); case OrderBy.None: return(records.ToList()); default: throw new NotSupportedException($"Sort type '{orderby}' is not supported!"); } } }