Skip to content

Commit fd7685f

Browse files
authored
#214 Update README.md with DefaultAzureCredential example
1 parent 6a6ee3d commit fd7685f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,37 @@ public static class Program
156156
}
157157
}
158158
```
159+
### Example: Using `DefaultAzureCredential`
160+
161+
To use Azure Managed Identity or other Azure SDK credential flows with this sink, you can provide an existing `TableServiceClient` instance constructed with `DefaultAzureCredential`. This is especially useful for Azure-hosted environments where connection strings are discouraged.
162+
163+
```csharp
164+
using Azure.Data.Tables;
165+
using Azure.Identity;
166+
using Serilog;
167+
168+
// Replace with your actual Azure Table Storage endpoint
169+
string tableEndpoint = "https://yourstorageaccountname.table.core.windows.net/";
170+
171+
// Create DefaultAzureCredential
172+
var credential = new DefaultAzureCredential();
173+
174+
// Create TableServiceClient with the endpoint and credential
175+
var tableServiceClient = new TableServiceClient(new Uri(tableEndpoint), credential);
176+
177+
// Configure Serilog to use the TableServiceClient
178+
var log = new LoggerConfiguration()
179+
.WriteTo.AzureTableStorage(
180+
tableServiceClient: tableServiceClient,
181+
storageTableName: "LogEvent"
182+
// [other options as desired]
183+
)
184+
.CreateLogger();
185+
```
186+
187+
> **Note:**
188+
> The `AzureTableStorage` sink will use the provided `TableServiceClient` for all operations.
189+
> The `DefaultAzureCredential` will automatically select the most appropriate authentication mechanism depending on your environment: Azure Managed Identity, Visual Studio sign-on, Azure CLI, etc.
159190
160191
### Change Log
161192

0 commit comments

Comments
 (0)