CreateLogStream() public method

Creates a log stream for the specified log group.

There is no limit on the number of log streams that you can create for a log group.

You must use the following guidelines when naming a log stream:

  • Log stream names must be unique within the log group.

  • Log stream names can be between 1 and 512 characters long.

  • The ':' (colon) and '*' (asterisk) characters are not allowed.

/// A parameter is specified incorrectly. /// /// The specified resource already exists. /// /// The specified resource does not exist. /// /// The service cannot complete the request. ///
public CreateLogStream ( CreateLogStreamRequest request ) : Amazon.CloudWatchLogs.Model.CreateLogStreamResponse
request Amazon.CloudWatchLogs.Model.CreateLogStreamRequest Container for the necessary parameters to execute the CreateLogStream service method.
return Amazon.CloudWatchLogs.Model.CreateLogStreamResponse
示例#1
0
 /// <summary>
 /// 创建一个新的日志流并开始记录
 /// </summary>
 /// <param name="client">AWS 客户端</param>
 /// <param name="groupName">日志组名称</param>
 /// <param name="streamName">日志流名称</param>
 /// <returns></returns>
 public static CloudWatchLogger CreateStream( AmazonCloudWatchLogsClient client, string groupName, string streamName )
 {
     var response = client.CreateLogStream( new CreateLogStreamRequest { LogGroupName = groupName, LogStreamName = streamName } );
       return new CloudWatchLogger( client, groupName, streamName );
 }
        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();
            }
        }