Home > Articles > Details

[EF Core] How to Enable Sensitive Data Logging and Detailed Errors

Question: How do you enable sensitive data and detailed error #logging in the #Development Environment for debugging purposes? EF Core does not show detailed errors. 


Please Login to see the rest of the answer
Answer: Keep in mind that Sensitive data logging is not advisable in production along with Detailed Error logging. Enable these flags at your own risk in Production.
See the code below on how to enable Detailed Error and Sensitive Data logging in Asp.net Core and Entity Framework Core.

 services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("dbConnection"),
                    sqlServerOptionsAction: sqlOptions =>
                    {
                        //Solves the issue of dropping the connection to the DB
                        sqlOptions.EnableRetryOnFailure(
                        maxRetryCount: 20,
                        maxRetryDelay: TimeSpan.FromSeconds(38),
                        errorNumbersToAdd: null);
                    }).EnableSensitiveDataLogging().EnableDetailedErrors());


- When injecting a Database Context into a Dependency Injection Container, it is safe to inject it as a Transient and not a Scopped Service.


If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy