Skip to content

Commit 4bf7631

Browse files
authored
Merge pull request #231920 from amerjusupovic/ajusupovic/troubleshoot-logs
Add troubleshooting logs section to ASP.NET and .NET core dynamic configuration guides
2 parents 2f13fb0 + 8bacbd9 commit 4bf7631

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,48 @@ The configuration refresh is triggered by the incoming requests to your web app.
230230

231231
![Launching updated quickstart app locally](./media/quickstarts/aspnet-core-app-launch-local-after.png)
232232

233+
## Logging and monitoring
234+
235+
Logs are output upon configuration refresh and contain detailed information on key-values retrieved from your App Configuration store and configuration changes made to your application.
236+
237+
- A default `ILoggerFactory` is added automatically when `services.AddAzureAppConfiguration()` is invoked. The App Configuration provider uses this `ILoggerFactory` to create an instance of `ILogger`, which outputs these logs. ASP.NET Core uses `ILogger` for logging by default, so you don't need to make additional code changes to enable logging for the App Configuration provider.
238+
- Logs are output at different log levels. The default level is `Information`.
239+
240+
| Log Level | Description |
241+
|---|---|
242+
| Debug | Logs include the key and label of key-values your application monitors for changes from your App Configuration store. The information also includes whether the key-value has changed compared with what your application has already loaded. Enable logs at this level to troubleshoot your application if a configuration change didn't happen as expected. |
243+
| Information | Logs include the keys of configuration settings updated during a configuration refresh. Values of configuration settings are omitted from the log to avoid leaking sensitive data. You can monitor logs at this level to ensure your application picks up expected configuration changes. |
244+
| Warning | Logs include failures and exceptions that occurred during configuration refresh. Occasional occurrences can be ignored because the configuration provider will continue using the cached data and attempt to refresh the configuration next time. You can monitor logs at this level for repetitive warnings that may indicate potential issues. For example, you rotated the connection string but forgot to update your application. |
245+
246+
You can enable logging at the `Debug` log level by adding the following example to your `appsettings.json` file. This example applies to all other log levels as well.
247+
```json
248+
"Logging": {
249+
"LogLevel": {
250+
"Microsoft.Extensions.Configuration.AzureAppConfiguration": "Debug"
251+
}
252+
}
253+
```
254+
- The logging category is `Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh`, which appears before each log. Here are some example logs at each log level:
255+
```console
256+
dbug: Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh[0]
257+
Key-value read from App Configuration. Change:'Modified' Key:'ExampleKey' Label:'ExampleLabel' Endpoint:'https://examplestore.azconfig.io'
258+
259+
info: Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh[0]
260+
Setting updated. Key:'ExampleKey'
261+
262+
warn: Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh[0]
263+
A refresh operation failed while resolving a Key Vault reference.
264+
Key vault error. ErrorCode:'SecretNotFound' Key:'ExampleKey' Label:'ExampleLabel' Etag:'6LaqgBQM9C_Do2XyZa2gAIfj_ArpT52-xWwDSLb2hDo' SecretIdentifier:'https://examplevault.vault.azure.net/secrets/ExampleSecret'
265+
```
266+
267+
Using `ILogger` is the preferred method in ASP.NET applications and is prioritized as the logging source if an instance of `ILoggerFactory` is present. However, if `ILoggerFactory` is not available, logs can alternatively be enabled and configured through the [instructions for .NET Core apps](./enable-dynamic-configuration-dotnet-core.md#logging-and-monitoring). For more information, see [logging in .NET Core and ASP.NET Core](/aspnet/core/fundamentals/logging).
268+
269+
> [!NOTE]
270+
> Logging is available if you use version **6.0.0** or later of any of the following packages.
271+
> - `Microsoft.Extensions.Configuration.AzureAppConfiguration`
272+
> - `Microsoft.Azure.AppConfiguration.AspNetCore`
273+
> - `Microsoft.Azure.AppConfiguration.Functions.Worker`
274+
233275
## Clean up resources
234276

235277
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-core.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,47 @@ Calling the `ConfigureRefresh` method alone won't cause the configuration to ref
140140
> [!NOTE]
141141
> Since the cache expiration time was set to 10 seconds using the `SetCacheExpiration` method while specifying the configuration for the refresh operation, the value for the configuration setting will only be updated if at least 10 seconds have elapsed since the last refresh for that setting.
142142

143+
## Logging and monitoring
144+
145+
Logs are output upon configuration refresh and contain detailed information on key-values retrieved from your App Configuration store and configuration changes made to your application. If you have an ASP.NET Core application, see these instructions for [Logging and Monitoring in ASP.NET Core](./enable-dynamic-configuration-aspnet-core.md#logging-and-monitoring). Otherwise, you can enable logging using the instructions for [logging with the Azure SDK](/dotnet/azure/sdk/logging).
146+
147+
- Logs are output at different event levels. The default level is `Informational`.
148+
149+
| Event Level | Description |
150+
|---|---|
151+
| Verbose | Logs include the key and label of key-values your application monitors for changes from your App Configuration store. The information also includes whether the key-value has changed compared with what your application has already loaded. Enable logs at this level to troubleshoot your application if a configuration change didn't happen as expected. |
152+
| Informational | Logs include the keys of configuration settings updated during a configuration refresh. Values of configuration settings are omitted from the log to avoid leaking sensitive data. You can monitor logs at this level to ensure your application picks up expected configuration changes. |
153+
| Warning | Logs include failures and exceptions that occurred during configuration refresh. Occasional occurrences can be ignored because the configuration provider will continue using the cached data and attempt to refresh the configuration next time. You can monitor logs at this level for repetitive warnings that may indicate potential issues. For example, you rotated the connection string but forgot to update your application. |
154+
155+
You can enable logging at the `Verbose` event level by specifying the `EventLevel.Verbose` parameter, as done in the following example. These instructions apply to all other event levels as well. This example also enables logs for only the `Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh` category.
156+
```csharp
157+
using var listener = new AzureEventSourceListener((eventData, text) =>
158+
{
159+
if (eventData.EventSource.Name == "Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh")
160+
{
161+
Console.WriteLine("[{1}] {0}: {2}", eventData.EventSource.Name, eventData.Level, text);
162+
}
163+
}, EventLevel.Verbose);
164+
```
165+
- The logging category is `Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh`, which appears before each log. Here are some example logs at each event level:
166+
```console
167+
[Verbose] Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh:
168+
Key-value read from App Configuration. Change:'Modified' Key:'ExampleKey' Label:'ExampleLabel' Endpoint:'https://examplestore.azconfig.io'
169+
170+
[Informational] Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh:
171+
Setting updated. Key:'ExampleKey'
172+
173+
[Warning] Microsoft-Extensions-Configuration-AzureAppConfiguration-Refresh:
174+
A refresh operation failed while resolving a Key Vault reference.
175+
Key vault error. ErrorCode:'SecretNotFound' Key:'ExampleKey' Label:'ExampleLabel' Etag:'6LaqgBQM9C_Do2XyZa2gAIfj_ArpT52-xWwDSLb2hDo' SecretIdentifier:'https://examplevault.vault.azure.net/secrets/ExampleSecret'
176+
```
177+
178+
> [!NOTE]
179+
> Logging is available if you use version **6.0.0** or later of any of the following packages.
180+
> - `Microsoft.Extensions.Configuration.AzureAppConfiguration`
181+
> - `Microsoft.Azure.AppConfiguration.AspNetCore`
182+
> - `Microsoft.Azure.AppConfiguration.Functions.Worker`
183+
143184
## Clean up resources
144185

145186
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]

0 commit comments

Comments
 (0)