将 CreateLogStream 与 AWS SDK 或 CLI 配合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

CreateLogStream 与 AWS SDK 或 CLI 配合使用

以下代码示例演示如何使用 CreateLogStream

.NET
SDK for .NET
注意

查看 GitHub,了解更多信息。查找完整示例,了解如何在 AWS 代码示例存储库中进行设置和运行。

using System; using System.Threading.Tasks; using Amazon.CloudWatchLogs; using Amazon.CloudWatchLogs.Model; /// <summary> /// Shows how to create an Amazon CloudWatch Logs stream for a CloudWatch /// log group. /// </summary> public class CreateLogStream { public static async Task Main() { // This client object will be associated with the same AWS Region // as the default user on this system. If you need to use a // different AWS Region, pass it as a parameter to the client // constructor. var client = new AmazonCloudWatchLogsClient(); string logGroupName = "cloudwatchlogs-example-loggroup"; string logStreamName = "cloudwatchlogs-example-logstream"; var request = new CreateLogStreamRequest { LogGroupName = logGroupName, LogStreamName = logStreamName, }; var response = await client.CreateLogStreamAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"{logStreamName} successfully created for {logGroupName}."); } else { Console.WriteLine("Could not create stream."); } } }
  • 有关 API 详细信息,请参阅《AWS SDK for .NET API Reference》中的 CreateLogStream

CLI
AWS CLI

以下命令将在日志组 my-logs 中创建一个名为 20150601 的日志流:

aws logs create-log-stream --log-group-name my-logs --log-stream-name 20150601
  • 有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 CreateLogStream