-1

I have the following code to add logs to log analytics:

private static readonly HttpClient httpClient = MakeClient();

private static HttpClient MakeClient()
{
    var client = new HttpClient();
    client.DefaultRequestHeaders.Add("Log-Type", "ApplicationLog");
    return client;
}

On running this, I get the below exception:

The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing. The operation was canceled. The operation was canceled. The read operation failed, see inner exception. Cannot access a disposed object. Object name: 'SslStream'.

on this line:

var response = await httpClient.SendAsync(
    CreateRequest(HttpMethod.Post, url, scheme, parameter, dateString, serializedMessage, contentType));

What am I missing?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
user989988
  • 3,006
  • 7
  • 44
  • 91
  • 1
    what is the inner exception? – Vivek Nuna Dec 20 '22 at 14:45
  • Does this answer your question? [Cannot make Polly Timeout Policy override the HttpClient default timeout](https://stackoverflow.com/questions/63473924/cannot-make-polly-timeout-policy-override-the-httpclient-default-timeout) – Peter Csala Dec 20 '22 at 16:42

1 Answers1

2

HttpClient has a default timeout of 100 sec. You can set the value based on your requirements.

httpClient.Timeout = TimeSpan.FromMinutes(10);

For refrence

ShubhamWagh
  • 565
  • 2
  • 9