You can customize the Search API client, for example, by using a custom HTTP client, or by changing the user agent information.

To customize individual requests, for example, with headers or query parameters, see Request options.

Custom HTTP requester

You can create your own client for making HTTP requests when initializing the API client, by creating a class that implements IHttpRequester.

1
2
3
4
using Algolia.Search.Clients;

var config = new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
var client = new SearchClient(config, new CustomRequester());

Custom user agent

If you want to customize the user agent for your requests, use the addAlgoliaAgentSegment method.

1
2
3
4
5
6
using Algolia.Search.Clients;

var searchConfig = new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

searchConfig.UserAgent.AddSegment("custom c# client", "optional version");
var client = new SearchClient(searchConfig);

This appends “custom c# client (optional version)” to the user-agent header.

Logging

You can set a custom logger to enable more or less logging output:

1
2
3
4
5
6
7
8
9
10
using Algolia.Search.Clients;
using Microsoft.Extensions.Logging;

var loggerFactory = LoggerFactory.Create(builder =>
{
  // Log everything from Algolia in the console, including debug logs
  builder.AddFilter("Algolia", LogLevel.Debug).AddConsole();
});

var client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", loggerFactory);
Did you find this page helpful?
C# API clients v7