Exemplo n.º 1
0
        /// <summary>
        /// Вернуть записи логов в определенном формате
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <List <ErrorResponse> > GetLogsInFormat(DiasErrorsRequest request)
        {
            List <ErrorResponse> errorResponses = new List <ErrorResponse>();
            DateTime             temp;

            _seqConnection = new SeqConnection(_configuration["SeqUrl"], "autxb7drQIW5afVHz4Nz");
            if (!_seqConnection.EnsureConnectedAsync(new TimeSpan(100)).IsCompleted)
            {
                _seqConnection = new SeqConnection(_configuration["SeqUrl"], "autxb7drQIW5afVHz4Nz");
            }

            List <LogsRequest> logs = new List <LogsRequest>();

            //все записи в базе по указанным фильтрам
            string lastReadEventId = null;
            string level           = "Error";

            while (true)
            {
                var resultSetFull = await _seqConnection.Events.InSignalAsync(
                    filter : $"@Level = '{level}'",
                    render : true,
                    fromDateUtc : request.BeginDate,
                    toDateUtc : request.EndDate,
                    afterId : lastReadEventId,
                    count : request.Count == 0? 100 : request.Count);

                foreach (var evt in resultSetFull.Events)
                {
                    DateTime.TryParse(evt.Timestamp, out temp);

                    errorResponses.Add(new ErrorResponse()
                    {
                        Time    = temp,
                        Header  = evt.Properties.Find(x => x.Name == "header")?.Value?.ToString() ?? (evt.Properties.Find(x => x.Name == "SourceContext")?.Value?.ToString() ?? "System"),
                        Host    = evt.Properties.Find(x => x.Name == "host")?.Value?.ToString() ?? "" + " " + $"({evt.Properties.Find(x => x.Name == "ip")?.Value?.ToString() ?? ""})",
                        Login   = evt.Properties.Find(x => x.Name == "login")?.Value?.ToString() ?? "",
                        Message = evt.Properties.Find(x => x.Name == "message")?.Value?.ToString() ?? evt.RenderedMessage
                    });
                }

                if (resultSetFull.Statistics.Status != ResultSetStatus.Partial)
                {
                    break;
                }

                lastReadEventId = resultSetFull.Statistics.LastReadEventId;
            }

            return(errorResponses);
        }
Exemplo n.º 2
0
 public async Task <List <ErrorResponse> > GetDiasErrors(DiasErrorsRequest request)
 {
     return(await _logService.GetLogsInFormat(request));
 }