zzzprojects / Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
https://dapper-plus.net/
380 stars 84 forks source link

ILogger not logging, but Console.WriteLine works? #126

Closed VictorioBerra closed 1 year ago

VictorioBerra commented 1 year ago

            this.logger.LogInformation("Starting bulk stuff..."); // WORKS

            await transaction
                .UseBulkOptions(options =>
                {
                    options.BatchSize = this.workDayStoreLocationsServiceOptions.DapperPlusBulkOperationBatchSize;
                    options.BatchTimeout = this.workDayStoreLocationsServiceOptions.DapperPlusBulkOperationBatchTimeout;
                    options.RetryCount = this.workDayStoreLocationsServiceOptions.DapperPlusBulkOperationRetryCount;

                    // options.Log = s => this.logger.LogInformation("Working..."); // DOES NOT WORK
                    options.Log = s => Console.WriteLine("Working..."); // WORKS!
                })
                .BulkActionAsync(
                    x => x.BulkSynchronize(
                            LocationsMappings.DatabaseLocationMappingKey,
                            locationEntities)
                        .Include(x =>
                            x.ThenBulkSynchronize(
                                LocationsMappings.DatabaseLocationTypeMappingKey,
                                location => location.LocationTypes))
                    cancellationToken);

I am using Serilog and I get logging output everywhere but BulkOptions ... options.Log does not ever seem to work with ILogger.

Any ideas?

JonathanMagnan commented 1 year ago

Hello @VictorioBerra ,

Could you try the code again without being async? So without the BulkActionAsync.

We are currently unsure why this issue happens, but we are pretty sure it caused because the code is being executed asynchronously.

I found this question on Stack Overflow, perhaps you will find an explanation from it. Some parts look pretty much like yours.

Let me know if you need more help with this issue.

Best Regards,

Jon

VictorioBerra commented 1 year ago

Turns out I had a filter excluding specific messages, sorry about that. Looks like its working as intended! Thanks for checking StackOverflow that helped point me in the right direction.

JonathanMagnan commented 1 year ago

Awesome @VictorioBerra ,

Thank you for letting us know.

Have a great day,

Best Regards,

Jon