> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apitally.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Configure the Apitally SDK for .NET.

You can configure Apitally when registering the service in your `Program.cs` file or in your `appsettings.json` file.

<CodeGroup>
  ```csharp Program.cs {6-9} theme={null}
  using Apitally;

  var builder = WebApplication.CreateBuilder(args);
  builder.Services.AddApitally(options =>
  {
      options.ClientId = "your-client-id";
      options.Env = "dev";
      options.RequestLogging.Enabled = true;
      // other parameters ...
  });

  var app = builder.Build();
  app.UseApitally();
  ```

  ```json appsettings.json {3-8} theme={null}
  {
    "Apitally": {
      "ClientId": "your-client-id",
      "Env": "dev",
      "RequestLogging": {
        "Enabled": true,
        // other parameters ...
      }
    }
  }
  ```
</CodeGroup>

## Parameters

The following configuration parameters are available. Only `ClientId` and `Env` are required.

| Parameter        | Description                                                                                                       | Type                    |
| :--------------- | :---------------------------------------------------------------------------------------------------------------- | :---------------------- |
| `ClientId`       | Client ID for your application. Find it on the *Setup instructions* page for your app.                            | `string`                |
| `Env`            | Name of the environment, e.g. `prod` or `dev`. The environment will be automatically created if it doesn't exist. | `string`                |
| `RequestLogging` | Configuration for request logging. See table below.                                                               | `RequestLoggingOptions` |

The `RequestLogging` parameter is an object with the following properties:

| Parameter                | Description                                                                                                                           | Type                                            | Default |
| :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------------- | :------ |
| `Enabled`                | Whether request logging is enabled.                                                                                                   | `bool`                                          | `false` |
| `IncludeQueryParams`     | Whether to include query parameters in the logs. If disabled, these will be stripped from the request URLs logged.                    | `bool`                                          | `true`  |
| `IncludeRequestHeaders`  | Whether to include request headers in the logs. Default masking for common sensitive headers (e.g. `Authorization`) applies.          | `bool`                                          | `false` |
| `IncludeRequestBody`     | Whether to include the request body in the logs. Only JSON and text are supported, up to 50 KB.                                       | `bool`                                          | `false` |
| `IncludeResponseHeaders` | Whether to include response headers in the logs.                                                                                      | `bool`                                          | `true`  |
| `IncludeResponseBody`    | Whether to include the response body in the logs. Only JSON and text are supported, up to 50 KB.                                      | `bool`                                          | `false` |
| `IncludeException`       | Whether to include exception details in the logs.                                                                                     | `bool`                                          | `true`  |
| `CaptureLogs`            | Whether to capture application logs emitted during request handling.                                                                  | `bool`                                          | `false` |
| `CaptureTraces`          | Whether to enable tracing using `System.Diagnostics`.                                                                                 | `bool`                                          | `false` |
| `QueryParamMaskPatterns` | List of regular expressions for matching query parameters to mask. These are in addition to the default masking patterns.             | `List<string>`                                  | `[]`    |
| `HeaderMaskPatterns`     | List of regular expressions for matching headers to mask. These are in addition to the default masking patterns.                      | `List<string>`                                  | `[]`    |
| `BodyFieldMaskPatterns`  | List of regular expressions for matching request/response body fields to mask. These are in addition to the default masking patterns. | `List<string>`                                  | `[]`    |
| `PathExcludePatterns`    | List of regular expressions for matching paths to exclude from logging.                                                               | `List<string>`                                  | `[]`    |
| `MaskRequestBody`        | Function to mask sensitive data in the request body. Return `null` to mask the whole body.                                            | <nobr>`Func<Request, byte[]?>`</nobr>           | -       |
| `MaskResponseBody`       | Function to mask sensitive data in the response body. Return `null` to mask the whole body.                                           | <nobr>`Func<Request, Response, byte[]?>`</nobr> | -       |
| `ShouldExclude`          | Function to determine whether a request should be excluded from logging. Return `true` to exclude the request.                        | <nobr>`Func<Request, Response, bool>`</nobr>    | -       |
