DescribeLogStreams() public method

Lists the log streams for the specified log group. You can list all the log streams or filter the results by prefix. You can also control how the results are ordered.

This operation has a limit of five transactions per second, after which transactions are throttled.

/// A parameter is specified incorrectly. /// /// The specified resource does not exist. /// /// The service cannot complete the request. ///
public DescribeLogStreams ( DescribeLogStreamsRequest request ) : DescribeLogStreamsResponse
request Amazon.CloudWatchLogs.Model.DescribeLogStreamsRequest Container for the necessary parameters to execute the DescribeLogStreams service method.
return Amazon.CloudWatchLogs.Model.DescribeLogStreamsResponse
Esempio n. 1
0
        /// <summary>
        /// 附加到现有日志流并开始记录
        /// </summary>
        /// <param name="client">AWS 客户端</param>
        /// <param name="groupName">日志组名称</param>
        /// <param name="streamName">日志流名称</param>
        /// <returns></returns>
        public static CloudWatchLogger AppendStream( AmazonCloudWatchLogsClient client, string groupName, string streamName )
        {
            var response = client.DescribeLogStreams( new DescribeLogStreamsRequest { OrderBy = OrderBy.LogStreamName, LogGroupName = groupName, LogStreamNamePrefix = streamName, Limit = 1 } );
              var streamInfo = response.LogStreams.FirstOrDefault();

              if ( streamInfo == null || streamInfo.LogStreamName != streamName )
            return CreateStream( client, groupName, streamName );

              return new CloudWatchLogger( client, groupName, streamName, streamInfo.UploadSequenceToken );
        }
        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();
            }
        }