Membuat tugas ekspor CloudWatch Log menggunakan AWS SDK - CloudWatch Log Amazon

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Membuat tugas ekspor CloudWatch Log menggunakan AWS SDK

Contoh kode berikut menunjukkan cara membuat tugas ekspor CloudWatch Log baru.

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh KodeAWS.

using System; using System.Threading.Tasks; using Amazon.CloudWatchLogs; using Amazon.CloudWatchLogs.Model; /// <summary> /// Shows how to create an Export Task to export the contents of the Amazon /// CloudWatch Logs to the specified Amazon Simple Storage Service (Amazon S3) /// bucket. The example was created with the AWS SDK for .NET version 3.7 and /// .NET Core 5.0. /// </summary> public class CreateExportTask { 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 taskName = "export-task-example"; string logGroupName = "cloudwatchlogs-example-loggroup"; string destination = "doc-example-bucket"; var fromTime = 1437584472382; var toTime = 1437584472833; var request = new CreateExportTaskRequest { From = fromTime, To = toTime, TaskName = taskName, LogGroupName = logGroupName, Destination = destination, }; var response = await client.CreateExportTaskAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"The task, {taskName} with ID: " + $"{response.TaskId} has been created successfully."); } } }

Untuk daftar lengkap panduan pengembang AWS SDK dan contoh kode, lihatMenggunakan CloudWatch Log dengan AWS SDK. Topik ini juga mencakup informasi tentang cara memulai dan detail versi-versi SDK sebelumnya.