internal PutLogsResponse PutLogs(PutLogsRequest request, LogGroup logGroup) { if (logGroup.LogsCount > LogConsts.LIMIT_LOG_COUNT) { throw new LogException("InvalidLogSize", "logItems' length exceeds maximum limitation: " + LogConsts.LIMIT_LOG_COUNT + " lines."); } else if (logGroup.SerializedSize > LogConsts.LIMIT_LOG_SIZE) { throw new LogException("InvalidLogSize", "logItems' size exceeds maximum limitation: " + LogConsts.LIMIT_LOG_SIZE + " byte."); } ServiceRequest sReq = new ServiceRequest(); sReq.Method = HttpMethod.Post; sReq.Endpoint = BuildReqEndpoint(request); //use empty string to replace Logstore if not set by user explicitly string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty; sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore; FillCommonHeaders(sReq); FillCommonParameters(sReq); sReq.Headers.Add(LogConsts.NAME_HEADER_CONTENTTYPE, LogConsts.PBVALUE_HEADER_CONTENTTYPE); byte[] logBytes = logGroup.ToByteArray(); sReq.Headers[LogConsts.NAME_HEADER_BODYRAWSIZE] = logBytes.Length.ToString(); sReq.Headers.Add(LogConsts.NAME_HEADER_COMPRESSTYPE, LogConsts.VALUE_HEADER_COMPRESSTYPE_LZ4); logBytes = LogClientTools.CompressToLz4(logBytes); sReq.Headers.Add(LogConsts.NAME_HEADER_MD5, LogClientTools.GetMd5Value(logBytes)); sReq.Content = new MemoryStream(logBytes); ExecutionContext context = new ExecutionContext(); context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Post); context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey); using (ServiceResponse response = serviceClient.Send(sReq, context)) { LogClientTools.ResponseErrorCheck(response, context.Credentials); PutLogsResponse putLogResp = new PutLogsResponse(response.Headers); return(putLogResp); } }
/// <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())); }