Skip to content

Adopt source-generated logging for runtime hot paths#99

Merged
SebastianStehle merged 2 commits into
mainfrom
copilot/improve-logging-source-generation
May 26, 2026
Merged

Adopt source-generated logging for runtime hot paths#99
SebastianStehle merged 2 commits into
mainfrom
copilot/improve-logging-source-generation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

This updates the remaining high-traffic ILogger call sites to use LoggerMessage source generation instead of runtime template parsing. The change keeps the existing structured log shape while moving the formatting contract into compile-time generated helpers.

  • Logging migration

    • Added per-namespace LogMessages partial classes with [LoggerMessage] definitions.
    • Replaced direct log.Log*("...", ...) calls in messaging, flows, assets, and hosting with generated helper methods.
    • Covered both parameterized logs and exception-bearing logs without changing the emitted message contracts.
  • Touched runtime paths

    • Messaging consumers/subscriptions/transport cleaners across EF, Mongo, RabbitMQ, Kafka, Google Pub/Sub, Redis, and subscription fanout.
    • Flow execution and cron scheduling paths.
    • Asset store initialization and resize-service error paths.
    • Hosting timer error logging.
  • Correctness fixes folded into the migration

    • Fixed the Kafka log-level gate so Kafka logs are emitted only when the level is enabled.
    • Corrected cron log message wording/parameter ordering in the touched path.
    • Removed an EF-specific log message that incorrectly referred to a MongoDB ID.
  • Example

    internal static partial class LogMessages
    {
        [LoggerMessage(EventId = 1, Level = LogLevel.Error,
            Message = "Failed to consume message with type {type}.")]
        public static partial void FailedToConsumeMessage(
            ILogger logger,
            Exception exception,
            string type);
    }
    
    LogMessages.FailedToConsumeMessage(log, ex, source.TypeString);

Copilot AI requested a review from SebastianStehle May 26, 2026 17:10
@SebastianStehle SebastianStehle marked this pull request as ready for review May 26, 2026 17:36
@SebastianStehle SebastianStehle merged commit 0433f63 into main May 26, 2026
2 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.

2 participants