public CreateLogStream ( |
||
request | Container for the necessary parameters to execute the CreateLogStream service method. | |
Результат | Amazon.CloudWatchLogs.Model.CreateLogStreamResponse |
/// <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(); } }