Beispiel #1
0
    public async Task <List <LaobianLog> > GetLogsAsync(LaobianSite site, DateTime date,
                                                        CancellationToken cancellationToken = default)
    {
        var result  = new List <LaobianLog>();
        var logFile =
            (await _logFileRepository.SearchFilesAsync(
                 Path.Combine(site.ToString().ToLowerInvariant(), date.Year.ToString("D4"), $"{date.ToDate()}.log"),
                 cancellationToken: cancellationToken)).FirstOrDefault();

        if (!string.IsNullOrEmpty(logFile))
        {
            var logs = await _logFileRepository.ReadAsync(logFile, cancellationToken);

            if (!string.IsNullOrEmpty(logs))
            {
                using var sr = new StringReader(logs);
                string line;
                while ((line = await sr.ReadLineAsync()) != null)
                {
                    result.Add(JsonUtil.Deserialize <LaobianLog>(line));
                }
            }
        }

        return(result);
    }