Skip to content

Interpolated strings bind to string log overloads instead of FormattableString overloads #5155

Closed

Description

@devlead

Problem

The FormattableString overloads for logging added in #4698 (Information(FormattableString) etc. on LogExtensions and LoggingAliases) are only used when the argument is explicitly typed as FormattableString. An inline interpolated string such as

Information($"Hello {name}");

binds to Information(string value), because C# treats the conversion to string as the better one. The string is flattened before it reaches the log, so the arguments aren't highlighted in the console output.

Findings

  • [OverloadResolutionPriority(1)] (C# 13, available since we target net10.0+) on the FormattableString overloads would make interpolated strings prefer them. Plain strings and Information("{0}", value) would be unaffected, since a plain string isn't an interpolated string.
  • That attribute has no effect in .cake scripts unless MethodAliasGenerator also emits it on the generated alias proxy methods.
  • Routing interpolated strings through FormatParser/PropertyToken would expose two existing parser bugs:
    • Alignment, e.g. $"{x,10}", throws FormatException.
    • Formats containing :, e.g. $"{now:HH:mm:ss}", lose their colons and render as HHmmss.

Expected

Information($"Hello {name}") (and Error/Warning/Verbose/Debug, with or without a Verbosity argument) uses the FormattableString overload, in both C# and Cake scripts. Alignment and : formats render the same as string.Format.

Notes

This is a source-level behaviour change for custom ICakeLog implementations and mocks: for an inline $"...", they'd receive "Hello {0}", [name] instead of "{0}", ["Hello name"].

Activity

  1. added this to the v7.0.0 milestone on Oct 22, 2026
  2. added a commit that references this issue on Oct 22, 2026
  3. added a commit that references this issue on Oct 27, 2026
  4. github-actions commented on Nov 10, 2026

    @github-actions

    🎉 This issue has been resolved in version v7.0.0 🎉

    The release is available on:

    Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions