tencent cloud

14天试用边缘安全加速平台 EO 限时免费

文档反馈

对象存储

日志管理

最后更新时间:2024-01-05 14:14:08

简介

本文档提供关于日志管理的 API 概览以及 SDK 示例代码。
API
操作名
操作描述
设置日志管理
为源存储桶开启日志记录
查询日志管理
查询源存储桶的日志配置信息

设置日志管理

功能说明

PUT Bucket logging 用于为源存储桶开启日志记录,将源存储桶的访问日志保存到指定的目标存储桶中。

示例代码

try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developer
string bucket = "examplebucket-1250000000";
PutBucketLoggingRequest request = new PutBucketLoggingRequest(bucket);
// 设置保存日志的目标路径
request.SetTarget("targetbucket-1250000000", "logs/");
//执行请求
PutBucketLoggingResult result = cosXml.PutBucketLogging(request);
//请求成功
Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
//请求失败
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
//请求失败
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
说明
更多完整示例,请前往 GitHub 查看。

查询日志管理

功能说明

GET Bucket logging 用于查询指定存储桶的日志配置信息。

示例代码

try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developer
string bucket = "examplebucket-1250000000";
GetBucketLoggingRequest request = new GetBucketLoggingRequest(bucket);
//执行请求
GetBucketLoggingResult getResult = cosXml.GetBucketLogging(request);
//请求成功
BucketLoggingStatus status = getResult.bucketLoggingStatus;
if (status != null && status.loggingEnabled != null) {
string targetBucket = status.loggingEnabled.targetBucket;
string targetPrefix = status.loggingEnabled.targetPrefix;
}
}
catch (COSXML.CosException.CosClientException clientEx)
{
//请求失败
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
//请求失败
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
说明
更多完整示例,请前往 GitHub 查看。

产品类别

联系我们

联系我们,为您的业务提供专属服务。

技术支持

如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

7x24 电话支持
中国香港
+852 800 906 020 (免费)
美国
+1 844 606 0804 (免费)
英国
+44 808 196 4551 (免费)
加拿大
+1 888 605 7930 (免费)
澳大利亚
+61 1300 986 386 (免费)
EdgeOne 热线
+852 300 80699
更多本地服务热线陆续新增中