AWS CloudWatchLogs不会使用DescribeLogStreamsRequest按降序返回日志



我正在使用C#AWS SDK重新定时CloudWatch登录(日期-时间(降序(最新优先(。因此,按如下方式设置AmazonCloudWatchLogsClient

AmazonCloudWatchLogsConfig config = new AmazonCloudWatchLogsConfig {
RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("<aws-region>")
};
AmazonCloudWatchLogsClient _client = new AmazonCloudWatchLogsClient(config);
_client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest {
LogGroupName = "logGroup",
OrderBy = "LastEventTime",
Descending = true,
});

并建立云观察组和流如下:

_client.CreateLogGroupAsync(new CreateLogGroupRequest { LogGroupName = "logGroup" });
_client.CreateLogStreamAsync(new CreateLogStreamRequest {
LogGroupName = "logGroup",
LogStreamName = "logStream"
});

检索云监视日志如下:

var request = new GetLogEventsRequest
{
LogStreamName = "logStream",
LogGroupName = "logGroup",
StartTime = DateTime.UtcNow.AddDays(-1),
EndTime = DateTime.UtcNow,
Limit = 50,
StartFromHead = false
};
var response = await GetLogEventsAsync(123, 456, 50, "000/f", "000/b");
var logs = response.Events;

logs始终接收最早的第一个,而不是最近的第一个

请提出任何修复建议。

参考编号:https://docs.aws.amazon.com/sdkfornet/latest/apidocs/items/TCloudWatchLogsDescribeLogStreamsRequestNET45.html

Shakel,我想知道您是否尝试过扩展方法OrderByDescending?我能够通过使用来实现这一点

returnValue.AddRange(logEventsResponse.Events.OrderByDescending(y => y.Timestamp).Select(x => new CloudWatchLogEvent { Message = x.Message, Timestamp = x.Timestamp.AddHours(-5), StreamName = stream.LogStreamName }));

returnValue类型为List<CloudWatchLogEvent>,logEventsResponse类型为Task<GetLogEventsResponse>,CloudWatchLogEvent是我创建的一个简单类:

public class CloudWatchLogEvent
{
public string Message { get; set; }
public DateTime Timestamp { get; set; }
public string StreamName { get; set; }
}

相关内容

  • 没有找到相关文章

最新更新