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

Interpolated string in log functions #49

Open
nojaf opened this issue Jan 4, 2024 · 4 comments
Open

Interpolated string in log functions #49

nojaf opened this issue Jan 4, 2024 · 4 comments

Comments

@nojaf
Copy link
Contributor

nojaf commented Jan 4, 2024

Related to https://g-research.github.io/fsharp-analyzers/analyzers/LoggingArgFuncNotFullyAppliedAnalyzer.html
Would it be interesting to also have an analyzer that detects a log call with a single interpolated string?
Instead of using the log message template.

let p = 42

// ❌
logger.Log(LogLevel.Information, $"foo %i{p}")

// ✅
logger.Log(LogLevel.Information, "foo {p}", p)

Would do you think @Smaug123?

@Smaug123
Copy link
Contributor

Smaug123 commented Jan 4, 2024

Interesting - probably yes, but one I would prefer to have would be "not all templated args have been given values".

@nojaf
Copy link
Contributor Author

nojaf commented Jan 4, 2024

That would be something like warn for logger.Log(LogLevel.Information, "foo {p} {x}", p) because there is no value for x?

@Smaug123
Copy link
Contributor

Smaug123 commented Jan 4, 2024

That would be something like warn for logger.Log(LogLevel.Information, "foo {p} {x}", p) because there is no value for x?

Yes, exactly.

@Numpsy
Copy link
Contributor

Numpsy commented Jan 5, 2024

There's a whole family of these sort of things in NetAnalyers, e.g.
https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca2254
https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca2017
https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca2253

Also - some related things in this Serilog Analyzer - https://github.com/Suchiman/SerilogAnalyzer#serilog003-property-binding-verifier

(I don't know if there's any general view on porting Roslyn analyzers, or how such things should be grouped.)

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

No branches or pull requests

3 participants