示例#1
0
        public static LogListDto WithLinks(
            this LogListDto dto,
            IUrlHelper urlHelper,
            ApiVersion apiVersion)
        {
            dto.Links = new List <LinkDto>
            {
                new LinkDto(
                    urlHelper.Link(nameof(LogsController.GetLogs),
                                   new
                {
                    dto.start,
                    dto.end,
                    version = apiVersion.ToString()
                }),
                    "self",
                    System.Net.Http.HttpMethod.Get.Method)
            };

            return(dto);
        }
示例#2
0
        public ActionResult GetLogs(
            [FromQuery(Name = "start")] DateTimeOffset start,
            [FromQuery(Name = "end")] DateTimeOffset end,
            ApiVersion apiVersion)
        {
            LogListDto logsDto = new LogListDto
            {
                start = start,
                end   = end,
                Logs  = MemorySink
                        .GetInstance()
                        .GetLogs(start, end)
                        .Select(logEvent =>
                                new LogDto
                {
                    Timestamp = logEvent.Timestamp,
                    Message   = logEvent.RenderMessage(),
                    Level     = logEvent.Level.ToString()
                })
                        .OrderBy(logDto => logDto.Timestamp),
            };

            return(Ok(logsDto.WithLinks(Url, apiVersion)));
        }