Пример #1
0
 /// 开启存储桶日志服务
 public void PutBucketLogging()
 {
     //.cssg-snippet-body-start:[put-bucket-logging]
     try
     {
         string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
         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());
     }
     //.cssg-snippet-body-end
 }
Пример #2
0
        public void TestBucketLogging()
        {
            try
            {
                PutBucketLoggingRequest request = new PutBucketLoggingRequest(bucket);

                request.SetTarget("bucket-cssg-source-1253653367", "/abc");
                PutBucketLoggingResult putResult = cosXml.PutBucketLogging(request);

                Assert.IsTrue(putResult.httpCode == 200);

                GetBucketLoggingResult getResult = cosXml.GetBucketLogging(new GetBucketLoggingRequest(bucket));
                Assert.AreEqual(getResult.httpCode, 200);

                // Console.WriteLine(getResult.GetResultInfo());
                Assert.IsNotEmpty((getResult.GetResultInfo()));
                Assert.IsNotEmpty(getResult.RawContentBodyString);

                BucketLoggingStatus status = getResult.bucketLoggingStatus;

                Assert.NotNull(status);
                Assert.NotNull(status.loggingEnabled);
                Assert.NotNull(status.GetInfo());

                string targetBucket = status.loggingEnabled.targetBucket;
                string targetPrefix = status.loggingEnabled.targetPrefix;
                Assert.NotNull(targetBucket);
                Assert.NotNull(targetPrefix);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());

                if (serverEx.statusCode != 409 && serverEx.statusCode != 451)
                {
                    Assert.Fail();
                }
            }
        }