microsoft / microsoft/aspire

Migrate Pomelo MySqlConnector logging away from obsolete MySqlConnectorLogManager.Provider

Open
#14,554 0 comments 0 reactions 0 assignees View on GitHub
area-integrations
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.