c# - Enable raw SQL logging in Entity Framework Core -


how enable logging of dbcommand raw sql queries?

i have added following code startup.cs file, not see log entries entity framework core.

void configureservices(iservicecollection services) {     services.addlogging(); }  public void configure(iapplicationbuilder app, ihostingenvironment env, iloggerfactory loggerfactory) {     loggerfactory.addconsole(configuration.getsection("logging"));     loggerfactory.adddebug(loglevel.debug); } 

i'm expecting see this:

microsoft.entityframeworkcore.storage.internal.relationalcommandbuilder... select [t].[id], [t].[datecreated], [t].[name], [t].[username] [trips] [t] 

figured out - need configure dbcontext use logger factory.

protected override void onconfiguring(dbcontextoptionsbuilder optionsbuilder) {     base.onconfiguring(optionsbuilder);      optionsbuilder.useloggerfactory(_loggerfactory); } 

Comments