Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateReplaySafeLogger<T> should return ILogger<T> instead of ILogger #365

Open
cgillum opened this issue Jan 22, 2025 · 2 comments
Open
Labels
breaking change This issue can only be delivered as part of a breaking change release.

Comments

@cgillum
Copy link
Member

cgillum commented Jan 22, 2025

Issue

Various engineering teams use ILogger<T> instead of ILogger with source generation. However, the CreateReplaySafeLogger<T> method returns an ILogger, creating an incompatibility with these practices.

Suggested fix

Change CreateReplaySafeLogger<T> to return ILogger<T>.

This is not a source-breaking change, but it is a binary-breaking change. We should make a decision about whether this meets the bar for a breaking-change release, or whether we should include this as a minor version release (with appropriate documentation) that can be released sooner.

/cc @jviau

@cgillum cgillum added the breaking change This issue can only be delivered as part of a breaking change release. label Jan 22, 2025
@jviau
Copy link
Member

jviau commented Jan 22, 2025

For now I recommend we change the implementation to return ILogger<T> (not signature though, callers will need to cast). Consumers will need to cast for the time being. We can continue to track this issue and change the return type in the next major version rev.

@jviau
Copy link
Member

jviau commented Jan 22, 2025

Also want to point out that if a caller needs ILogger<T>, they can always wrap the ILogger returned by CreateReplaySafeLogger<T> in their own shim. There is no special additional logic needed for ILogger<T> . The default implementation of ILogger<T> is just that - a wrapper around ILogger.

https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LoggerT.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change This issue can only be delivered as part of a breaking change release.
Projects
None yet
Development

No branches or pull requests

2 participants