in src/AWS.Logger.Core/Core/AWSLoggerCore.cs [450:506]
private async Task<string> LogEventTransmissionSetup(CancellationToken token)
{
string serviceURL = GetServiceUrl();
if (!_config.DisableLogGroupCreation)
{
var logGroupResponse = await _client.Value.DescribeLogGroupsAsync(new DescribeLogGroupsRequest
{
LogGroupNamePrefix = _config.LogGroup
}, token).ConfigureAwait(false);
if (!IsSuccessStatusCode(logGroupResponse))
{
LogLibraryServiceError(new System.Net.WebException($"Lookup LogGroup {_config.LogGroup} returned status: {logGroupResponse.HttpStatusCode}"), serviceURL);
}
if (logGroupResponse.LogGroups?.FirstOrDefault(x => string.Equals(x.LogGroupName, _config.LogGroup, StringComparison.Ordinal)) == null)
{
var createGroupResponse = await _client.Value.CreateLogGroupAsync(new CreateLogGroupRequest { LogGroupName = _config.LogGroup }, token).ConfigureAwait(false);
if (!IsSuccessStatusCode(createGroupResponse))
{
LogLibraryServiceError(new System.Net.WebException($"Create LogGroup {_config.LogGroup} returned status: {createGroupResponse.HttpStatusCode}"), serviceURL);
}
else if (_config.NewLogGroupRetentionInDays.HasValue && _config.NewLogGroupRetentionInDays.Value > 0)
{
// If CreateLogGroup returns a success status code then this process is responsible for applying the retention policy.
// This prevents a case of multiple instances each trying to set the retention policy.
PutRetentionPolicy(_config.NewLogGroupRetentionInDays.Value,_config.LogGroup, serviceURL, token);
}
}
}
var currentStreamName = GenerateStreamName(_config);
try
{
var streamResponse = await _client.Value.CreateLogStreamAsync(new CreateLogStreamRequest
{
LogGroupName = _config.LogGroup,
LogStreamName = currentStreamName
}, token).ConfigureAwait(false);
if (!IsSuccessStatusCode(streamResponse))
{
LogLibraryServiceError(new System.Net.WebException($"Create LogStream {currentStreamName} for LogGroup {_config.LogGroup} returned status: {streamResponse.HttpStatusCode}"), serviceURL);
}
}
catch (ResourceAlreadyExistsException) when (!string.IsNullOrEmpty(_config.LogStreamName))
{
}
catch (Exception ex)
{
LogLibraryServiceError(new Exception($"Create LogStream {currentStreamName} for LogGroup {_config.LogGroup} returned error: {ex.Message}"), serviceURL);
}
_repo = new LogEventBatch(_config.LogGroup, currentStreamName, Convert.ToInt32(_config.BatchPushInterval.TotalSeconds), _config.BatchSizeInBytes);
return currentStreamName;
}