使用 Amazon 软件开发工具包描述 CloudWatch Logs 日志组 - Amazon CloudWatch Logs
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

使用 Amazon 软件开发工具包描述 CloudWatch Logs 日志组

以下代码示例说明了如何描述 CloudWatch Logs 日志组。

.NET
Amazon SDK for .NET

public static async Task Main() { // Creates a CloudWatch Logs client using the default // user. If you need to work with resources in another // AWS Region than the one defined for the default user, // pass the AWS Region as a parameter to the client constructor. var client = new AmazonCloudWatchLogsClient(); var request = new DescribeLogGroupsRequest { Limit = 5, }; var response = await client.DescribeLogGroupsAsync(request); if (response.LogGroups.Count > 0) { do { response.LogGroups.ForEach(lg => { Console.WriteLine($"{lg.LogGroupName} is associated with the key: {lg.KmsKeyId}."); Console.WriteLine($"Created on: {lg.CreationTime.Date.Date}"); Console.WriteLine($"Date for this group will be stored for: {lg.RetentionInDays} days.\n"); }); } while (response.NextToken is not null); } }
  • GitHub 中查找说明和更多代码。

  • 有关 API 详细信息,请参阅 Amazon SDK for .NET API 参考中的 DescribeLogGroups

有关 Amazon 开发工具包开发人员指南和代码示例的完整列表,包括帮助入门和有关早期版本的信息,请参阅 将 CloudWatch Logs 与 Amazon 开发工具包结合使用