linq2db.EntityFrameworkCore icon indicating copy to clipboard operation
linq2db.EntityFrameworkCore copied to clipboard

Log sql query strings when executing InsertWhenNotMatched, UpdateWhenMatched

Open abrasat opened this issue 1 year ago • 0 comments

I am using the linq2db package to implement a "upsert" for a Oracle database. Is it possible to configure the library to produce logs containing the generated sql queries? I added this at the application initialization:

... MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Debug)

but only the execution of the "original" ef core commands is logged, not of those using linq2db. At the application startup the logger factory is created as follows (to be able to log also the startup code):

    using var loggerFactory = LoggerFactory.Create(logging =>
    {
           logging.AddSerilog(serilogLogger);
    });

Then later in the initialization of the application the logger factory is added as singleton:

....
var host = Host.CreateDefaultBuilder()
    .ConfigureServices((context, services) =>
    {
            services
               // ...
                .Configure<OraDbSettings>(configuration.GetSection("OraDbSettings"))
                .AddDbContextFactory<myDbContext>(
                           options => 
                                options
                                    .UseOracle(
                                        oraConnString
                                        )
                                    .UseLoggerFactory(loggerFactory)
                                    .UseExceptionProcessor()
                                    .EnableSensitiveDataLogging()

                                )
                 .AddSingleton(loggerFactory)
 ......

I dont know what is the reason why the execution od the linq2db commands is not logged. A "regular" ef core database command is logged like this:

17-11-2023 11:58:02.988 +01:00:: DBG:: 2023-11-17 11:58:02.988655 ThreadID:1   (SQL)     OracleRelationalCommand.ExecuteReaderAsync() : SELECT "d"."ID" "Id", "d"."NAME" "Name", "d"."TITLE" "Title" FROM ...

The linq2db command generates only this log entry:

17-11-2023 11:58:03.514 +01:00:: DBG:: 2023-11-17 11:58:03.514929 ThreadID:1   (EXIT)    OracleRelationalCommand.ExecuteReaderAsync()

abrasat avatar Nov 17 '23 10:11 abrasat