public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.CloudWatchLogs.Model.PutLogEventsRequest(); if (cmdletContext.LogEvent != null) { request.LogEvents = cmdletContext.LogEvent; } if (cmdletContext.LogGroupName != null) { request.LogGroupName = cmdletContext.LogGroupName; } if (cmdletContext.LogStreamName != null) { request.LogStreamName = cmdletContext.LogStreamName; } if (cmdletContext.SequenceToken != null) { request.SequenceToken = cmdletContext.SequenceToken; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
/// <summary> /// Initiates the asynchronous execution of the PutLogEvents operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLogEvents operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<PutLogEventsResponse> PutLogEventsAsync(PutLogEventsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutLogEventsRequestMarshaller(); var unmarshaller = PutLogEventsResponseUnmarshaller.Instance; return InvokeAsync<PutLogEventsRequest,PutLogEventsResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Uploads a batch of log events to the specified log stream. /// /// /// <para> /// Every PutLogEvents request must include the <code class="code">sequenceToken</code> /// obtained from the response of the previous request. An upload in a newly created log /// stream does not require a <code class="code">sequenceToken</code>. /// </para> /// /// <para> /// The batch of events must satisfy the following constraints: <ul> <li>The maximum /// batch size is 1,048,576 bytes, and this size is calculated as the sum of all event /// messages in UTF-8, plus 26 bytes for each log event.</li> <li>None of the log events /// in the batch can be more than 2 hours in the future.</li> <li>None of the log events /// in the batch can be older than 14 days or the retention period of the log group.</li> /// <li>The log events in the batch must be in chronological ordered by their <code class="code">timestamp</code>.</li> /// <li>The maximum number of log events in a batch is 10,000.</li> </ul> /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the PutLogEvents service method.</param> /// /// <returns>The response from the PutLogEvents service method, as returned by CloudWatchLogs.</returns> /// <exception cref="Amazon.CloudWatchLogs.Model.DataAlreadyAcceptedException"> /// /// </exception> /// <exception cref="Amazon.CloudWatchLogs.Model.InvalidParameterException"> /// Returned if a parameter of the request is incorrectly specified. /// </exception> /// <exception cref="Amazon.CloudWatchLogs.Model.InvalidSequenceTokenException"> /// /// </exception> /// <exception cref="Amazon.CloudWatchLogs.Model.OperationAbortedException"> /// Returned if multiple requests to update the same resource were in conflict. /// </exception> /// <exception cref="Amazon.CloudWatchLogs.Model.ResourceNotFoundException"> /// Returned if the specified resource does not exist. /// </exception> /// <exception cref="Amazon.CloudWatchLogs.Model.ServiceUnavailableException"> /// Returned if the service cannot complete the request. /// </exception> public PutLogEventsResponse PutLogEvents(PutLogEventsRequest request) { var marshaller = new PutLogEventsRequestMarshaller(); var unmarshaller = PutLogEventsResponseUnmarshaller.Instance; return Invoke<PutLogEventsRequest,PutLogEventsResponse>(request, marshaller, unmarshaller); }
void Writer(object sender, ElapsedEventArgs e) { try { var logEvents = new List<InputLogEvent>(); var more = true; while (more) { InputLogEvent item; more = items.TryTake(out item); if (more) logEvents.Add(item); } if (logEvents.Count == 0) return; if (!Settings.Default.SendUsageData) return; using (var logs = new AmazonCloudWatchLogsClient(AwsKeys.AccessKey, AwsKeys.SecretKey, RegionEndpoint.APSoutheast2)) { var request = new PutLogEventsRequest(AwsKeys.GroupName, LogStreamName, logEvents); var describeLogStreamsRequest = new DescribeLogStreamsRequest(AwsKeys.GroupName); var describeLogStreamsResponse = logs.DescribeLogStreams(describeLogStreamsRequest); var logStreams = describeLogStreamsResponse.LogStreams; var logStream = logStreams.FirstOrDefault(ls => ls.LogStreamName == LogStreamName); if (logStream != null) { var token = logStream.UploadSequenceToken; request.SequenceToken = token; checkResponse(logs.PutLogEvents(request)); } else { var createRequest = new CreateLogStreamRequest(AwsKeys.GroupName, LogStreamName); checkResponse(logs.CreateLogStream(createRequest)); checkResponse(logs.PutLogEvents(request)); } } } catch(Exception ee) { TraceInfo.WriteLine(ee.Message); TraceDebug.WriteLine(ee.StackTrace); } finally { if(timer != null) timer.Start(); } }
/// <summary> /// Initiates the asynchronous execution of the PutLogEvents operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLogEvents operation on AmazonCloudWatchLogsClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutLogEvents /// operation.</returns> public IAsyncResult BeginPutLogEvents(PutLogEventsRequest request, AsyncCallback callback, object state) { var marshaller = new PutLogEventsRequestMarshaller(); var unmarshaller = PutLogEventsResponseUnmarshaller.Instance; return BeginInvoke<PutLogEventsRequest>(request, marshaller, unmarshaller, callback, state); }
private Amazon.CloudWatchLogs.Model.PutLogEventsResponse CallAWSServiceOperation(IAmazonCloudWatchLogs client, Amazon.CloudWatchLogs.Model.PutLogEventsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudWatch Logs", "PutLogEvents"); try { #if DESKTOP return(client.PutLogEvents(request)); #elif CORECLR return(client.PutLogEventsAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
private static void FlushBufferToCloudWatchLogs() { var request = new PutLogEventsRequest { LogGroupName = _logGroup, LogStreamName = _logStream, SequenceToken = _sequenceToken }; lock (BUFFER_LOCK) { if (_cwlBuffer.Count == 0) return; foreach (var message in _cwlBuffer) { request.LogEvents.Add( new InputLogEvent { Message = message, Timestamp = DateTime.Now }); } _cwlBuffer.Clear(); } lock(SEQUENCE_LOCK) { var response = _cwlClient.PutLogEventsAsync(request).Result; _sequenceToken = response.NextSequenceToken; } }
IAsyncResult invokePutLogEvents(PutLogEventsRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new PutLogEventsRequestMarshaller(); var unmarshaller = PutLogEventsResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
/// <summary> /// Initiates the asynchronous execution of the PutLogEvents operation. /// <seealso cref="Amazon.CloudWatchLogs.IAmazonCloudWatchLogs"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLogEvents operation on AmazonCloudWatchLogsClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutLogEvents /// operation.</returns> public IAsyncResult BeginPutLogEvents(PutLogEventsRequest request, AsyncCallback callback, object state) { return invokePutLogEvents(request, callback, state, false); }
/// <summary> /// Uploads a batch of log events to the specified log stream. /// /// /// <para> /// Every PutLogEvents request must include the <code class="code">sequenceToken</code> /// obtained from the response of the previous request. An upload in a newly created log /// stream does not require a <code class="code">sequenceToken</code>. /// </para> /// /// <para> /// The batch of events must satisfy the following constraints: <ul> <li>The maximum /// batch size is 32,768 bytes, and this size is calculated as the sum of all event messages /// in UTF-8, plus 26 bytes for each log event.</li> <li>None of the log events in the /// batch can be more than 2 hours in the future.</li> <li>None of the log events in the /// batch can be older than 14 days or the retention period of the log group.</li> <li>The /// log events in the batch must be in chronological ordered by their <code class="code">timestamp</code>.</li> /// <li>The maximum number of log events in a batch is 1,000.</li> </ul> /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the PutLogEvents service method.</param> /// /// <returns>The response from the PutLogEvents service method, as returned by CloudWatchLogs.</returns> /// <exception cref="DataAlreadyAcceptedException"> /// /// </exception> /// <exception cref="InvalidParameterException"> /// Returned if a parameter of the request is incorrectly specified. /// </exception> /// <exception cref="InvalidSequenceTokenException"> /// /// </exception> /// <exception cref="OperationAbortedException"> /// Returned if multiple requests to update the same resource were in conflict. /// </exception> /// <exception cref="ResourceNotFoundException"> /// Returned if the specified resource does not exist. /// </exception> /// <exception cref="ServiceUnavailableException"> /// Returned if the service cannot complete the request. /// </exception> public PutLogEventsResponse PutLogEvents(PutLogEventsRequest request) { IAsyncResult asyncResult = invokePutLogEvents(request, null, null, true); return EndPutLogEvents(asyncResult); }
/// <summary> /// Uploads a batch of log events to the specified log stream. /// /// /// <para> /// Every PutLogEvents request must include the <code class="code">sequenceToken</code> /// obtained from the response of the previous request. An upload in a newly created log /// stream does not require a <code class="code">sequenceToken</code>. /// </para> /// /// <para> /// The batch of events must satisfy the following constraints: <ul> <li>The maximum /// batch size is 32,768 bytes, and this size is calculated as the sum of all event messages /// in UTF-8, plus 26 bytes for each log event.</li> <li>None of the log events in the /// batch can be more than 2 hours in the future.</li> <li>None of the log events in the /// batch can be older than 14 days or the retention period of the log group.</li> <li>The /// log events in the batch must be in chronological ordered by their <code class="code">timestamp</code>.</li> /// <li>The maximum number of log events in a batch is 1,000.</li> </ul> /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the PutLogEvents service method.</param> /// /// <returns>The response from the PutLogEvents service method, as returned by CloudWatchLogs.</returns> /// <exception cref="DataAlreadyAcceptedException"> /// /// </exception> /// <exception cref="InvalidParameterException"> /// Returned if a parameter of the request is incorrectly specified. /// </exception> /// <exception cref="InvalidSequenceTokenException"> /// /// </exception> /// <exception cref="OperationAbortedException"> /// Returned if multiple requests to update the same resource were in conflict. /// </exception> /// <exception cref="ResourceNotFoundException"> /// Returned if the specified resource does not exist. /// </exception> /// <exception cref="ServiceUnavailableException"> /// Returned if the service cannot complete the request. /// </exception> public PutLogEventsResponse PutLogEvents(PutLogEventsRequest request) { var task = PutLogEventsAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }