Verwendung von CreateLogStream mit einem AWS-SDK oder CLI - AWS-SDK-Codebeispiele

Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs verfügbar.

Verwendung von CreateLogStream mit einem AWS-SDK oder CLI

Die folgenden Code-Beispiele zeigen, wie CreateLogStream verwendet wird.

.NET
SDK für .NET
Anmerkung

Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel- einrichten und ausführen.

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."); } } }
  • Weitere API-Informationen finden Sie unter CreateLogStream in der AWS SDK für .NET-API-Referenz.

CLI
AWS CLI

Im folgenden Beispiel wird ein Protokollstream mit dem Namen 20150601 in der Protokollgruppe my-logs erstellt.

aws logs create-log-stream --log-group-name my-logs --log-stream-name 20150601
  • Weitere API-Informationen finden Sie unter CreateLogStream in der AWS CLI-Befehlsreferenz.