I implemented an ORMLite IRequestLogger. I have an Async service that uses AutoQuery and it appears that when the first await is hit in that Async service (well before the API has returned a response), the logger code fires and attempts to log the API request, and the Log method gets called with response.Status property value of WaitingForActivation and a response.Result of null. How do I stop the Logger from attempting to log until the async API has completed?
Any progress here? It seems this issue is calling my API calls to fail intermittently with “An asynchronous module or handler completed while an asynchronous operation was still pending.” Since the logger code exits prior to the API call returning.
If it helps at all, here is my Log implementation:
public virtual async void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
{
var requestType = requestDto?.GetType();
if (ExcludeRequestType(requestType))
return;
var entry = CreateEntry(request, requestDto, response, requestDuration, requestType);
await Db.InsertAsync(entry).ConfigureAwait(false);
}
The issue with that is I get a deadlock because the API service is Async, which gives control to the Log when it tries to write to the DB, and therefore the log attempts to execute but stalls because it doesn’t have the return value yet from the API call.