AmazonCloudWatchLogs.DescribeLogGroupsAsync() is not working nor throwing any errors when invoked

0

Call to AmazonCloudWatchLogs.DescribeLogGroupsAsync() is not working nor throwing any errors when invoked.

1] Can you please share more inputs to resolve this issue / get errors logged for this call [or all AWS .NET API calls]?

2] Is there any additional settings / configurations we need to do so that error / catch block is invoked so we get logs about it?

We want to send logs to AWS CloudWatch for our internal/on-premise web application [this is actually hosted on internal cloud & .NET + Angular Web application] So we are using AWS .NET API i.e. AmazonCloudWatchLogs.DescribeLogGroupsAsync() & other related classes. We have wrapped call to this function with try catch block along with proper logging at all lines including catch block error logging but we are not getting any logs post call to AmazonCloudWatchLogs.DescribeLogGroupsAsync() & also logs in catch block also not invoked.

Below is sample code

For reference,

1] we only get logs till - _consoleLogger.LogInformation("Logger ctor - Calling DescribeLogGroupsAsync Start"); 2] & also log statement in catch block are not invoked.

Sample Code -

try
            {
                _consoleLogger.LogInformation("Logger ctor - Calling DescribeLogGroupsAsync Start");
                var existingLogGroups = _client.DescribeLogGroupsAsync();
                var result = existingLogGroups.ConfigureAwait(true).GetAwaiter().GetResult();
                _consoleLogger.LogInformation($"Logger ctor - NextToken is {result.NextToken}");
                _consoleLogger.LogInformation("Logger ctor - Calling DescribeLogGroupsAsync End");

                Initialise(_consoleLogger).Wait();
            }
            catch (AggregateException exception)
            {
                foreach (var inner in exception.InnerExceptions)
                {
                    _consoleLogger.LogError(inner, $"Logger ctor - AggregateException occured in Logger ctor");
                }
            }
            catch (Exception exception)
            {
                _consoleLogger.LogError(exception, $"Logger ctor - Exception occured in Logger Ctor");
            }
1 Answer
0

I would recommend not using GetAwaiter().GetResult() to avoid thread exhaustion and deadlock. Instead, simply write, var result= await _client.DescribeLogGroupsAsync(); You can see an example here -https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/dotnetv3/CloudWatchLogs/DescribeLogGroupsExample/DescribeLogGroups.cs

AWS
maykums
answered a year ago
  • Thanks. Initially, I had used both await _client.DescribeLogGroupsAsync() & also _client.DescribeLogGroupsAsync().Wait(), but not solution & still its not working.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions