Log SQL on .net core

//In dbcontext class (or startup.cs depending on your conf) optionsBuilder.UseSqlite("Filename=DB/mydb.sqlite", options => { options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName); }).EnableSensitiveDataLogging(); //NEW LINE //in appsettings.json "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information", "Microsoft.EntityFrameworkCore.Database.Command": "Information" //NEW LINE }
Before beginning :
- A Db must be configured (ex : sqlite, mysql, etc.)
- A logger must be configured (ex : NLog, etc.)

NB : Tested on .net core 3.1 api

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.