# Logging

In case you need to understand what your application is doing, the SurrealDB SDK has a built-in logging mechanism.

Logging is an important part of any application to understand what is happening. The .NET SDK supports the built-in logging API offered by the `Microsoft.Extensions.Logging` NuGet package.

## Logging categories

The SurrealDB SDK for .NET has a set of logging categories so that you can pick what you want to display, using the respective `LogLevel`.

Example:

```json
{
  "Logging": {
    "LogLevel": {
      "SurrealDB.Connection": "Information",
      "SurrealDB.Method": "Information",
      "SurrealDB.Query": "Information",
      "SurrealDB.Serialization": "Debug"
    }
  }
}
```

This example will enable the following logging features:

- `Connection` - Logger category for messages related to connection operations.
- `Method` - Logger category for method execution, excluding `Connect` method.
- `Query` - Logger category for messages related to written or generated queries, that can be executed within `Query` or `RawQuery`.
- `Serialization` - Logger category for data serialisation and deserialisation, e.g. hexa CBOR format exchanged between the client and a SurrealDB instance.

> [!IMPORTANT]
> `Serialization` logs are only displayed when on `Debug` level to prevent data exchanges exposure. Please be sure to only enable this feature when you can guarantee that no sensitive data will be exposed.

> [!NOTE]
> `Serialization` logs display data in a CBOR format. You might need to find tools that parses CBOR data and displays it in a more human way.

## Sensitive data

To prevent data leakage, the property <code>SensitiveDataLoggingEnabled</code> of <code>SurrealDbLoggingOptions</code> is set to <code>true</code> by default.

When the feature is enabled, any data that is passed to a SurrealDB method is replaced by the placeholder value `?`. Example:

![Logging displayed from a console application](LoggingConsoleImg)

If needed, you can override this option using the <code>EnableSensitiveDataLogging</code> when building a new <code>SurrealDbOptions</code> instance.

```csharp
services.AddSurreal(
  SurrealDbOptions
    .Create()
    .FromConnectionString(configuration.GetConnectionString("SurrealDB")!)
    .EnableSensitiveDataLogging(false)
    .Build()
);
```

> [!IMPORTANT]
> Please be sure to only enable this feature when you can guarantee that no sensitive data will be exposed.
