Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing on adding logs to Log Analytics

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?

like image 571
user989988 Avatar asked Oct 19 '25 08:10

user989988


1 Answers

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

httpClient.Timeout = TimeSpan.FromMinutes(10);

For refrence

like image 186
ShubhamWagh Avatar answered Oct 20 '25 22:10

ShubhamWagh