public void TestPutData()
        {
            LogClient client = new LogClient(ClientTestData.TEST_ENDPOINT, ClientTestData.TEST_ACCESSKEYID, ClientTestData.TEST_ACCESSKEY);

            client.SetWebSend(MockSend);
            LogGroup.Builder lgBuilder = LogGroup.CreateBuilder();
            lgBuilder.Topic  = "testTopic";
            lgBuilder.Source = "127.0.0.1";
            Aliyun.Api.LOG.Log.Builder logBuilder = Aliyun.Api.LOG.Log.CreateBuilder();
            logBuilder.Time = 1000;
            Aliyun.Api.LOG.Log.Types.Content.Builder contentBuilder = Aliyun.Api.LOG.Log.Types.Content.CreateBuilder();
            contentBuilder.Key   = "mockKey";
            contentBuilder.Value = "mockValue";
            logBuilder.AddContents(contentBuilder);
            lgBuilder.AddLogs(logBuilder);
            LogGroup tmpLogGroup = lgBuilder.Build();

            client.PutLogs(new PutLogsRequest(ClientTestData.TEST_PROJECT, "testlogstore"), tmpLogGroup);
            Assert.IsTrue(DicToString(Headers).CompareTo("[x-sls-apiversion:0.4.0][x-sls-bodyrawsize:49][x-sls-signaturemethod:hmac-sha1][Content-Type:application/x-protobuf][x-sls-compresstype:deflate][Content-MD5:3D1836DDC6585AD78B60CCAE90C075DF][User-Agent:aliyun-sdk-dotnet/1.0.0.0]") == 0);
            Assert.IsTrue(Host.CompareTo("mock_project.mockhost.aliyuncs.com") == 0);
            Assert.IsTrue(RequestUri.CompareTo("http://mock_project.mockhost.aliyuncs.com/logstores/testlogstore") == 0);
        }
Example #2
0
        /// <summary>
        /// put logs into sls server
        /// </summary>
        /// <param name="request">The request to put logs </param>
        /// <exception>LogException</exception>
        /// <returns>The response to put logs</returns>
        public PutLogsResponse PutLogs(PutLogsRequest request)
        {
            LogGroup.Builder lgBuilder = LogGroup.CreateBuilder();

            if (request.IsSetTopic())
            {
                lgBuilder.Topic = request.Topic;
            }

            if (request.IsSetSource())
            {
                lgBuilder.Source = request.Source;
            }
            else
            {
                lgBuilder.Source = _localMachinePrivateIp;  //use default machine private ip as source (should we
            }
            if (request.IsSetLogItems())
            {
                foreach (var item in request.LogItems)
                {
                    Log.Builder logBuilder = Log.CreateBuilder();
                    logBuilder.Time = item.Time;
                    foreach (var kv in item.Contents)
                    {
                        Log.Types.Content.Builder contentBuilder = Log.Types.Content.CreateBuilder();
                        contentBuilder.Key   = kv.Key;
                        contentBuilder.Value = kv.Value;
                        logBuilder.AddContents(contentBuilder);
                    }
                    lgBuilder.AddLogs(logBuilder);
                }
            }

            return(PutLogs(request, lgBuilder.Build()));
        }