|
| 1 | +--- |
| 2 | +sidebar_position: 9 |
| 3 | +sidebar_label: Logging |
| 4 | +title: Logging | .NET | SDK | Concepts |
| 5 | +description: In case you need to understand what your application is doing, the SurrealDB SDK has a built-in logging mechanism. |
| 6 | +--- |
| 7 | + |
| 8 | +import Image from "@components/Image.astro"; |
| 9 | +import LoggingConsoleImg from "@img/dotnet-logging-console.png"; |
| 10 | + |
| 11 | +# Logging |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +## Logging categories |
| 16 | + |
| 17 | +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`. |
| 18 | + |
| 19 | +Example: |
| 20 | + |
| 21 | +```bash |
| 22 | +{ |
| 23 | + "Logging": { |
| 24 | + "LogLevel": { |
| 25 | + "SurrealDB.Connection": "Information", |
| 26 | + "SurrealDB.Method": "Information", |
| 27 | + "SurrealDB.Query": "Information", |
| 28 | + "SurrealDB.Serialization": "Debug" |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +This example will enable the following logging features: |
| 35 | + |
| 36 | +* `Connection` - Logger category for messages related to connection operations. |
| 37 | +* `Method` - Logger category for method execution, excluding `Connect` method. |
| 38 | +* `Query` - Logger category for messages related to written or generated queries, that can be executed within `Query` or `RawQuery`. |
| 39 | +* `Serialization` - Logger category for data serialization and deserialization, e.g. hexa CBOR format exchanged between the client and a SurrealDB instance. |
| 40 | + |
| 41 | +> [!IMPORTANT] |
| 42 | +> `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. |
| 43 | +
|
| 44 | +## Sensitive data |
| 45 | + |
| 46 | +To prevent data leakage, the property <code>SensitiveDataLoggingEnabled</code> of <code>SurrealDbLoggingOptions</code> is set to <code>true</code> by default. |
| 47 | + |
| 48 | +When the feature is enabled, any data that is passed to a SurrealDB method is replaced by the placeholder value `?`. Example: |
| 49 | + |
| 50 | +<Image |
| 51 | + alt="Logging displayed from a console application" |
| 52 | + src={LoggingConsoleImg} |
| 53 | +/> |
| 54 | + |
| 55 | +If needed, you can override this option using the <code>EnableSensitiveDataLogging</code> when building a new <code>SurrealDbOptions</code> instance. |
| 56 | + |
| 57 | +```csharp |
| 58 | +services.AddSurreal( |
| 59 | + SurrealDbOptions |
| 60 | + .Create() |
| 61 | + .FromConnectionString(configuration.GetConnectionString("SurrealDB")!) |
| 62 | + .EnableSensitiveDataLogging(false) |
| 63 | + .Build() |
| 64 | +); |
| 65 | +``` |
| 66 | + |
| 67 | +> [!IMPORTANT] |
| 68 | +> Please be sure to only enable this feature when you can guarantee that no sensitive data will be exposed. |
0 commit comments