Skip to content

Roslyn Analyzer that pushes towards using the Format logger overloads instead of doing interpolation #283

@danielmarbach

Description

@danielmarbach

Describe the feature.

Is your feature related to a problem? Please describe.

No

Describe the requested feature

For log statements that do not require to log details of the exception prefer the *Format overloads like InfoFormat to allow logging libraries that support structured logging to extract the format template and the arguments. So instead of writing

Logger.Info($"Here is an informational log with {someValue}");

prefer

Logger.InfoFormat("Here is an informational log with {0}", someValue);

This allows semantic logger targets to easily filter on log message (Here is an informational log with {0}) and/or any of the provided arguments (0=='my value') where the first does not as that will only log strings without any context.

Describe alternatives you've considered

Given that we should move away from our current logging abstraction, investing time into such an analyzer might not be well spent but we leave it up to the people that take up this work to decide.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions