Skip to content

Commit f91085e

Browse files
authored
Follow-up overhaul updates (#36674)
1 parent 014c374 commit f91085e

2 files changed

Lines changed: 43 additions & 52 deletions

File tree

aspnetcore/fundamentals/configuration/index.md

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use the Configuration API to configure app settings in
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: tdykstra
77
ms.custom: mvc
8-
ms.date: 01/22/2026
8+
ms.date: 01/23/2026
99
uid: fundamentals/configuration/index
1010
---
1111
# Configuration in ASP.NET Core
@@ -234,14 +234,14 @@ public class Startup
234234

235235
public void ConfigureServices(IServiceCollection services)
236236
{
237-
var connectionString = Config["ConnectionStrings.DefaultConnection"]}");
237+
var connectionString = Config["ConnectionStrings.DefaultConnection"];
238238

239239
...
240240
}
241241

242242
public void Configure(...)
243243
{
244-
var defaultLogLevel = Config["Logging:LogLevel:Default"]}");
244+
var defaultLogLevel = Config["Logging:LogLevel:Default"];
245245

246246
...
247247
}
@@ -306,23 +306,23 @@ The Configuration API reads hierarchical configuration data by flattening the hi
306306
Consider the following hierarchical configuration data:
307307

308308
* :::no-loc text="ConnectionStrings":::
309-
* :::no-loc text="DefaultConnection (Value = ":::no-loc text="Data Source=LocalSqlServer\\MSSQLDev;":::")
309+
* :::no-loc text="DefaultConnection (Value = 'Data Source=LocalSqlServer\\MSSQLDev;')":::
310310
* :::no-loc text="Logging":::
311311
* :::no-loc text="LogLevel":::
312-
* :::no-loc text="Default"::: (Value = :::no-loc text="Information":::)
313-
* :::no-loc text="Microsoft"::: (Value = :::no-loc text="Warning":::)
314-
* :::no-loc text="Microsoft.Hosting.Lifetime"::: (Value = :::no-loc text="Information":::)
315-
* :::no-loc text="AllowedHosts"::: (Value = *)
312+
* :::no-loc text="Default (Value = 'Information')":::
313+
* :::no-loc text="Microsoft (Value = 'Warning')":::
314+
* :::no-loc text="Microsoft.Hosting.Lifetime (Value = 'Information')":::
315+
* :::no-loc text="AllowedHosts (Value = '*')":::
316316

317317
The following table displays the keys used to recover the values in the preceding configuration data. The delimiter isn't required for :::no-loc text="AllowedHosts":::.
318318

319319
Key (colon delimiter) | Key (double-underscore delimiter)
320320
--- | ---
321-
ConnectionStrings:DefaultConnection | ConnectionStrings__DefaultConnection
322-
Logging:LogLevel:Default | Logging__LogLevel__Default
323-
Logging:LogLevel:Microsoft | Logging__LogLevel__Microsoft
324-
Logging:LogLevel:Microsoft.Hosting.Lifetime | Logging__LogLevel__Microsoft.Hosting.Lifetime
325-
AllowedHosts | AllowedHosts
321+
`ConnectionStrings:DefaultConnection` | `ConnectionStrings__DefaultConnection`
322+
`Logging:LogLevel:Default` | `Logging__LogLevel__Default`
323+
`Logging:LogLevel:Microsoft` | `Logging__LogLevel__Microsoft`
324+
`Logging:LogLevel:Microsoft.Hosting.Lifetime` | `Logging__LogLevel__Microsoft.Hosting.Lifetime`
325+
`AllowedHosts` | `AllowedHosts`
326326

327327
> [!NOTE]
328328
> In complex app configuration scenarios, we recommend grouping and reading related hierarchical configuration data using the [Options pattern](xref:fundamentals/configuration/options).
@@ -416,7 +416,7 @@ Provider | Provides configuration from…
416416
[Custom configuration provider](#custom-configuration-provider) | Custom source
417417
[Environment Variables Configuration Provider](#environment-variables-configuration-provider) | Environment variables
418418
[File Configuration Provider](#file-configuration-provider) | INI, JSON, and XML files
419-
[Key-per-file Configuration Provider](#key-per-file-configuration-provider) | Directory files
419+
[Key-Per-File Configuration Provider](#key-per-file-configuration-provider) | Directory files
420420
[Memory Configuration Provider](#memory-configuration-provider) | In-memory collections
421421
[User secrets](xref:security/app-secrets) | File in the user profile directory
422422

@@ -986,9 +986,9 @@ The previous configuration loads the following keys with `value`:
986986
* `key:attribute`
987987
* `section:key:attribute`
988988

989-
## Key-per-file Configuration Provider
989+
## Key-Per-File Configuration Provider
990990

991-
The <xref:Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider> uses a directory's files as configuration key-value pairs. The key is the file name. The value contains the file's contents. The Key-per-file Configuration Provider is used in Docker hosting scenarios.
991+
The <xref:Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider> uses a directory's files as configuration key-value pairs. The key is the file name. The value contains the file's contents. The Key-Per-File Configuration Provider is used in Docker hosting scenarios.
992992

993993
To activate key-per-file configuration, call the <xref:Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile%2A> extension method on an instance of <xref:Microsoft.Extensions.Configuration.ConfigurationBuilder>. The `directoryPath` to the files must be an absolute path.
994994

@@ -1203,10 +1203,10 @@ spaces at the ends of the lines when editing the following content.
12031203
12041204
-->
12051205

1206-
> no-loc text="subsection0:key0 value: value200":::
1207-
> no-loc text="subsection0:key1 value: value201":::
1208-
> no-loc text="subsection1:key0 value: value210":::
1209-
> no-loc text="subsection1:key1 value: value211":::
1206+
> :::no-loc text="subsection0:key0 value: value200":::
1207+
> :::no-loc text="subsection0:key1 value: value201":::
1208+
> :::no-loc text="subsection1:key0 value: value210":::
1209+
> :::no-loc text="subsection1:key1 value: value211":::
12101210
12111211
## Bind an array
12121212

@@ -1381,7 +1381,7 @@ public class Program
13811381
{
13821382
config.AddInMemoryCollection(arrayDict);
13831383
config.AddJsonFile("Value3.json",
1384-
optional: false, reloadOnChange: false);
1384+
optional: false, reloadOnChange: false);
13851385
})
13861386
.ConfigureWebHostDefaults(webBuilder =>
13871387
{
@@ -1529,46 +1529,41 @@ Create the custom configuration provider by inheriting from <xref:Microsoft.Exte
15291529
::: moniker range=">= aspnetcore-6.0"
15301530

15311531
```csharp
1532-
public class EFConfigurationProvider : ConfigurationProvider
1533-
{
1534-
public EFConfigurationProvider(Action<DbContextOptionsBuilder> optionsAction)
1535-
{
1536-
OptionsAction = optionsAction;
1537-
}
1538-
1539-
Action<DbContextOptionsBuilder> OptionsAction { get; }
1532+
using Microsoft.EntityFrameworkCore;
15401533

1534+
public class EFConfigurationProvider(Action<DbContextOptionsBuilder> optionsAction) : ConfigurationProvider
1535+
{
15411536
public override void Load()
15421537
{
15431538
var builder = new DbContextOptionsBuilder<EFConfigurationContext>();
15441539

1545-
OptionsAction(builder);
1540+
optionsAction(builder);
15461541

1547-
using (var dbContext = new EFConfigurationContext(builder.Options))
1548-
{
1549-
if (dbContext == null || dbContext.Values == null)
1550-
{
1551-
throw new Exception("Null DB context");
1552-
}
1553-
dbContext.Database.EnsureCreated();
1542+
using var dbContext = new EFConfigurationContext(builder.Options);
15541543

1555-
Data = !dbContext.Values.Any()
1556-
? CreateAndSaveDefaultValues(dbContext)
1557-
: dbContext.Values.ToDictionary(c => c.Id, c => c.Value);
1544+
if (dbContext == null || dbContext.Values == null)
1545+
{
1546+
throw new Exception("Null DB context");
15581547
}
1548+
1549+
dbContext.Database.EnsureCreated();
1550+
1551+
Data = !dbContext.Values.Any()
1552+
? CreateAndSaveDefaultValues(dbContext)
1553+
: dbContext.Values.ToDictionary(c => c.Id, c => c.Value);
15591554
}
15601555

1561-
private static IDictionary<string, string> CreateAndSaveDefaultValues(
1556+
private static Dictionary<string, string> CreateAndSaveDefaultValues(
15621557
EFConfigurationContext dbContext)
15631558
{
15641559
// Quotes (c)2005 Universal Pictures: Serenity
15651560
// https://www.uphe.com/movies/serenity-2005
15661561
var configValues =
15671562
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
15681563
{
1569-
{ "quote1", "I aim to misbehave." },
1570-
{ "quote2", "I swallowed a bug." },
1571-
{ "quote3", "You can't stop the signal, Mal." }
1564+
{ "quote1", "I aim to misbehave." },
1565+
{ "quote2", "I swallowed a bug." },
1566+
{ "quote3", "You can't stop the signal, Mal." }
15721567
};
15731568

15741569
if (dbContext == null || dbContext.Values == null)
@@ -1674,8 +1669,8 @@ An `AddEFConfiguration` extension method permits adding the configuration source
16741669
public static class EntityFrameworkExtensions
16751670
{
16761671
public static IConfigurationBuilder AddEFConfiguration(
1677-
this IConfigurationBuilder builder,
1678-
Action<DbContextOptionsBuilder> optionsAction)
1672+
this IConfigurationBuilder builder,
1673+
Action<DbContextOptionsBuilder> optionsAction)
16791674
{
16801675
return builder.Add(new EFConfigurationSource(optionsAction));
16811676
}

aspnetcore/fundamentals/logging/index.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Learn how to use the ASP.NET Core logging framework provided by the
66
monikerRange: '>= aspnetcore-3.1'
77
ms.author: tdykstra
88
ms.custom: mvc
9-
ms.date: 01/15/2026
9+
ms.date: 01/23/2026
1010
uid: fundamentals/logging/index
1111
---
1212
# Logging in .NET and ASP.NET Core
@@ -541,18 +541,14 @@ The following `Counter` component logs from the `IncrementByOne` method with the
541541
private void IncrementByOne()
542542
{
543543
var logger = Logger.CreateLogger($"{typeof(Counter)}.IncrementByOne");
544-
545544
Logger.LogInformation("Someone incremented the counter!");
546-
547545
currentCount++;
548546
}
549547

550548
private void IncrementByTen()
551549
{
552550
var logger = Logger.CreateLogger($"{typeof(Counter)}.IncrementByTen");
553-
554551
Logger.LogInformation("Someone incremented the counter!");
555-
556552
currentCount += 10;
557553
}
558554
}
@@ -819,7 +815,7 @@ public async Task<TodoItem> GetTodoItem(long id)
819815

820816
using (Logger.BeginScope(new List<KeyValuePair<string, object>>
821817
{
822-
new KeyValuePair<string, object>("TransactionId", transactionId),
818+
new("TransactionId", transactionId),
823819
}))
824820
{
825821
Logger.LogInformation(LogEvent.GetItem, "Getting item {Id}", id);

0 commit comments

Comments
 (0)