Sasha Chernin
Sasha Chernin

Reputation: 67

Azure function app that sends log data to Azure Monitor causes socket exhaustion

I have function app that iterates over log files and sends them to Azure Log Analytics using this sample here: https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#c-sample

The problem is that I have many logs, so many instances of HttpClient are created, which causes "An attempt was made to access a socket in a way forbidden by its access permissions. ---> System.Net.Sockets.SocketException" error.

I know that is a better practice to create a static instance of HttpClient, but since such instance needs a different signature for each log in my case, its not possible.

Any ideas how can I overcome this error?

Upvotes: 1

Views: 377

Answers (1)

Matt Douhan
Matt Douhan

Reputation: 733

Why does it have to be in the default headers? you can create a httpRequestMessage and change the headers for each connection and still use a static client, the receiver does not know if you used defaultHeaders or not when creating the request.

This is fairly described here

Upvotes: 1

Related Questions