Base solution for your next web application
Open Closed

How to enable ef core`s logging #7190


User avatar
0
nicolaslau created

i try a normal way to enable ef core`s logging by setting in appsetting.json

"Logging": { "LogLevel": { "Microsoft.EntityFrameworkCore": "Debug" } }

but i cann`t see any sql logging in log file.


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi nicolaslau

    You can try this code.

    public static readonly LoggerFactory MyLoggerFactory
    	= new LoggerFactory(new[]
    	{
    		new Log4NetProvider("log4net.config")
    	});
    
    public static void Configure(DbContextOptionsBuilder<DbContext> dbContextOptions, string connectionString)
    {
    	dbContextOptions.UseLoggerFactory(MyLoggerFactory).UseMySql(connectionString);
    }
    
    public static void Configure(DbContextOptionsBuilder<DbContext> builder, DbConnection connection)
    {
    	builder.UseLoggerFactory(MyLoggerFactory).UseMySql(connection);
    }
    
    

    From: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3599#issue-339294569

  • User Avatar
    0
    nicolaslau created

    @maliming thanks.

    I add the logger factory from abp`s ILoggerFactory by DI.