Reputation: 173
I'm trying to use the AWS CloudWatch library for logging. Everything works fine with synchronous methods. However, when I try to use the async versions of the same methods, the code fails abruptly, with no exceptions thrown. This piece of line fails:
await _amazonCloudWatchLogsClient.PutLogEventsAsync(request);
While this line works fine:
_amazonCloudWatchLogsClient.PutLogEvents(request);
Interestingly, this line works as well:
var result = _amazonCloudWatchLogsClient.PutLogEventsAsync(request).Result;
At this point I can't think of a way other than going back to the synchronous methods. Again, this is true for all the async methods that I've tried, not for this particular method.
Upvotes: 3
Views: 1116
Reputation: 173
Apparently, you have to be careful while calling async methods. One problem in the calling chain will cause issues. In my case, 3 functions up the stack, a method was async with a return value of void.
public async void LogBatchThroughput
and I was calling this method like a regular method from a synchronous method. This was causing the last async method to be called (PutLogEventsAsync) to fail, silently. I changed the previous method signature to be:
public async Task LogBatchThroughput
and called it by .GetAwaiter().GetResult(), from a synchronous method.
This solved the issue. The issue didn't have anything to do with the AWS Cloudwatch libraries.
Upvotes: 1