turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

Not working with result.Content.ReadAsStringAsync() in a DelegatingHandler #349

Open jefflaia opened 6 years ago

jefflaia commented 6 years ago

I add a DelegatingHandler for logging in my current MVC API. I tried to use i18n for multiple languages support. But the response content is not translated.it returns original string with [[[]]]. My DelegatingHandler code like follows:

public class LogRequestResponseHandler : DelegatingHandler { ... protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // log request body ...

        // let other handlers process the request
        var result = await base.SendAsync(request, cancellationToken);

        // log response body
        string responseBody = string.Empty;
        if (result?.Content != null)
        {
            responseBody = await result.Content.ReadAsStringAsync();
        }
        _logger.Debug($"{request.RequestUri}, {request.Method.Method}, Status: {result.StatusCode} Success: {result.IsSuccessStatusCode}, Response body: {responseBody}");

        return result;
    }
}

it can work when I commented result.Content.ReadAsStringAsync() in above code.