Migrate Pomelo MySqlConnector logging away from obsolete MySqlConnectorLogManager.Provider
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Summary
The `Aspire.Pomelo.EntityFrameworkCore.MySql` integration uses `MySqlConnectorLogManager.Provider` to wire MySqlConnector's internal logging categories (e.g. `MySqlConnector.ConnectionPool`, `MySqlConnector.MySqlCommand`, `MySqlConnector.MySqlConnection`, `MySqlConnector.MySqlDataSource`) into the application's `ILoggerFactory`. This API was marked `[Obsolete]` in `MySqlConnector.DependencyInjection` 2.5.0 with the message:
> Use UseLoggerFactory or AddMySqlDataSource instead. See https://mysqlconnector.net/diagnostics/logging/
## Why we can't simply switch
The recommended replacement (`MySqlDataSourceBuilder.UseLoggerFactory()`) requires using `MySqlDataSource`-based connection management. However, Pomelo EF Core doesn't use `MySqlDataSource` — it takes a raw connection string via `dbContextOptionsBuilder.UseMySql(connectionString, ...)`.
We attempted switching to `dbContextOptionsBuilder.UseLoggerFactory(loggerFactory)` in #14549, but this only configures **EF Core's** logging, not **MySqlConnector's** internal logging. This caused conformance test failures because the MySqlConnector log categories were no longer present:
`
Assert.Contains() Failure: Item not found in collection
Not found: "MySqlConnector.ConnectionPool"
`
Customers may rely on these log categories being present, so removing them would be a breaking change.
## Current workaround
In #14549, we reverted to the obsolete API with a pragma warning disable CS0618 suppression.
## Options to investigate
1. **Use MySqlDataSourceBuilder with Pomelo**: Investigate whether Pomelo 9.0.0 supports receiving a `MySqlDataSource` instead of a connection string. If so, we could create a `MySqlDataSource` via `MySqlDataSourceBuilder` (which supports `.UseLoggerFactory()`) and pass it to Pomelo.
2. **Contribute upstream**: Work with the MySqlConnector team to provide a non-obsolete global logging API for scenarios where `MySqlDataSource` isn't used.
3. **Accept the suppression**: If neither option above is feasible, keep the pragma suppression and document why.
## Files involved
- `src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs` — line 99
- `tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/EnrichMySqlTests.cs` — line 36
- `tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/ConformanceTests.cs` — expected log categories list
## References
- PR that discovered this: #14549
- MySqlConnector logging docs: https://mysqlconnector.net/diagnostics/logging/
- MySqlDataSourceBuilder.UseLoggerFactory() API: https://mysqlconnector.net/api/mysqlconnector/mysqldatasourcebuilder/useloggerfactory/
Contributor guide
Assessment
This issue has not been assessed yet.