Skip to content

Adjust overloads and parameter order to resolve potential ambiguous method call errors #59

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

Merged
merged 2 commits into from
Apr 15, 2025

Conversation

tbdrake
Copy link
Contributor

@tbdrake tbdrake commented Apr 15, 2025

fixes #58

  • Remove new overloads that can cause ambiguity. See comments on this PR for details.
  • Move new optional parameters int? writeTimeoutMs = null, int? disposeTimeoutMs = null added in Fix infinite hang #51 to the end of the parameter lists of pre-existing methods to maintain signature compatibility with 2.x version of this library.
  • Fix the PingPonger app command line arg handling and add a call to TCPSink(string uri) to verify it is no longer an ambiguous method call.

Comment on lines -89 to -96
public static LoggerConfiguration TCPSink(
this LoggerSinkConfiguration loggerConfiguration,
string uri,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
{
return TCPSink(loggerConfiguration, uri, null, null, null, restrictedToMinimumLevel);
}

Copy link
Contributor Author

@tbdrake tbdrake Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overload was added in #51 and included in 3.0.0-alpha.1. Code like TCPSink("tcp://localhost:1234") would get an ambiguous call error because both this overload and the one above could match.

I think this one can be safely removed since it is only in an alpha release and the same functionality can be achieved using the overload above with args like TCPSink("tcp://localhost:1234") or TCPSink("tcp://localhost:1234", restrictedToMinimumLevel: logLevel)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added this because of #51 (comment).
But as we are going for a major, removing this is fine I guess?

Copy link
Contributor Author

@tbdrake tbdrake Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but I was thinking that rather than add that overload, we could address the concern in that comment by putting the new optional parameters writeTimeoutMs and disposeTimeoutMs at the end of the existing methods, e.g.

        public static LoggerConfiguration TCPSink(
            this LoggerSinkConfiguration loggerConfiguration,
            string uri,
            ITextFormatter? textFormatter = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int? writeTimeoutMs = null,
            int? disposeTimeoutMs = null)

That way, existing code that was calling that existing method like cfg.TCPSink("tcp://localhost:1234", new LogstashJsonFormatter(), LogEventLevel.Debug) would still work and be compatible with the new signature (it would use the default args writeTimeoutMs = null and disposeTimeoutMs = null).

Does that make sense and seem OK to you?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, works for me.

@tbdrake tbdrake changed the title Adjust overloads and parameter order Adjust overloads and parameter order to resolve potential ambiguous method call errors Apr 15, 2025
Comment on lines -52 to -56
public static LoggerConfiguration TCPSink(
this LoggerSinkConfiguration loggerConfiguration,
IPAddress ipAddress,
int port,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
Copy link
Contributor Author

@tbdrake tbdrake Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overload

        public static LoggerConfiguration TCPSink(
            this LoggerSinkConfiguration loggerConfiguration,
            IPAddress ipAddress,
            int port,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)

was added in #51 included in 3.0.0-alpha.1 but I think can be safely removed. It can cause ambiguous call errors with code like TCPSink(IPAddress.Parse("127.0.0.1"), 1234) because the overload above could also match.

I think this is OK to remove because the overload above can cover the same functionality/parameters with calls like this:
TCPSink(IPAddress.Parse("127.0.0.1"), 1234, restrictedToMinimumLevel: logLevel)

@tbdrake tbdrake marked this pull request as ready for review April 15, 2025 15:18
@nojaf nojaf merged commit f98a383 into serilog-contrib:master Apr 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overloads of NetworkLoggerConfigurationExtensions.TCPSink(string uri, ...) can cause ambiguous call errors
2 participants