Skip to content

Commit ad0b6c0

Browse files
authored
Switch from preproc check to env check (#35884)
1 parent 2f0088c commit ad0b6c0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

aspnetcore/blazor/blazor-ef-core.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,20 @@ public void Dispose() => Context?.Dispose();
229229

230230
<xref:Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.EnableSensitiveDataLogging%2A> includes application data in exception messages and framework logging. The logged data can include the values assigned to properties of entity instances and parameter values for commands sent to the database. Logging data with <xref:Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.EnableSensitiveDataLogging%2A> is a **security risk**, as it may expose passwords and other [Personally Identifiable Information (PII)](xref:blazor/security/index#personally-identifiable-information-pii) when it logs SQL statements executed against the database.
231231

232-
We recommend only enabling <xref:Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.EnableSensitiveDataLogging%2A> for development and testing:
232+
We recommend only enabling <xref:Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.EnableSensitiveDataLogging%2A> for local development and testing:
233233

234234
```csharp
235-
#if DEBUG
235+
if (builder.Environment.IsDevelopment())
236+
{
236237
services.AddDbContextFactory<ContactContext>(opt =>
237238
opt.UseSqlite($"Data Source={nameof(ContactContext.ContactsDb)}.db")
238239
.EnableSensitiveDataLogging());
239-
#else
240+
}
241+
else
242+
{
240243
services.AddDbContextFactory<ContactContext>(opt =>
241244
opt.UseSqlite($"Data Source={nameof(ContactContext.ContactsDb)}.db"));
242-
#endif
245+
}
243246
```
244247

245248
## Additional resources

0 commit comments

Comments
 (0)