Skip to content

Commit e0af8dc

Browse files
committed
feat: add logging section for .NET SDK
1 parent 0b19a2e commit e0af8dc

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

bun.lockb

0 Bytes
Binary file not shown.
753 KB
Loading

src/content/doc-sdk-dotnet/core/dependency-injection.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ We have added a new Connection String called <code>SurrealDB</code> with the def
2929
"AllowedHosts": "*",
3030
"Logging": {
3131
"LogLevel": {
32-
"Default": "Information",
33-
"Microsoft.AspNetCore": "Warning"
32+
"Default": "Information",
33+
"Microsoft.AspNetCore": "Warning"
3434
}
3535
},
3636
"ConnectionStrings": {
@@ -143,4 +143,4 @@ Then make sure your SurrealDB server is running on <code>127.0.0.1:8000</code> a
143143

144144
```sh
145145
dotnet run
146-
```
146+
```

src/content/doc-sdk-dotnet/core/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ In this section, we will go over the core concepts of the SurrealDB SDK for .NET
1717
- [Run SurrealQL queries](/docs/sdk/dotnet/core/writing-surrealql)
1818
- [Connection Strings](/docs/sdk/dotnet/core/connection-strings)
1919
- [Dependency Injection](/docs/sdk/dotnet/core/dependency-injection)
20-
21-
20+
- [Logging](/docs/sdk/dotnet/core/logging)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)