{"id":27455063,"url":"https://github.com/blokyk/ca2254-codefix","last_synced_at":"2026-04-29T01:32:21.874Z","repository":{"id":287790956,"uuid":"965767443","full_name":"Blokyk/ca2254-codefix","owner":"Blokyk","description":"A codefix for CA2254, to replace interpolated strings with a proper structred-logging friendly message","archived":false,"fork":false,"pushed_at":"2025-04-13T23:25:36.000Z","size":39,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T15:16:24.927Z","etag":null,"topics":["csharp","dotnet","roslyn","roslyn-codefix","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blokyk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-13T21:24:30.000Z","updated_at":"2025-04-13T23:22:00.000Z","dependencies_parsed_at":"2025-04-14T00:32:57.119Z","dependency_job_id":"83a420fa-2095-4dab-ba41-d24f1b2fff63","html_url":"https://github.com/Blokyk/ca2254-codefix","commit_stats":null,"previous_names":["blokyk/ca2254-codefix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blokyk%2Fca2254-codefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blokyk%2Fca2254-codefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blokyk%2Fca2254-codefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blokyk%2Fca2254-codefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blokyk","download_url":"https://codeload.github.com/Blokyk/ca2254-codefix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094935,"owners_count":21211837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","roslyn","roslyn-codefix","structured-logging"],"created_at":"2025-04-15T15:16:29.150Z","updated_at":"2026-04-29T01:32:21.845Z","avatar_url":"https://github.com/Blokyk.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `Blokyk.CA2254CodeFix`\n\nThe CA2254 diagnostic (`Template should be a static expression`) helps you\ndetect logger messages that could be problematic for structured logging, by\nflagging non-constant message templates, i.e. messages that contain expressions\nthemselves.\n\nMost notably, this includes interpolated strings (`$\"hello {user.name}!\"`),\nwhich can be pretty annoying to \"un-interpolate.\" This small roslyn codefix aims\nto address that! Here's an example:\n\n```cs\n// Before codefix, marked with CA2254\nlogger.LogDebug($\"User {user.Username} uploaded {documents.Count} documents!\");\n\n// After codefix\nlogger.LogDebug(\"User {Username} uploaded {Count} documents!\", user.Username, documents.Count);\n```\n\n## Installation\n\nThis codefix can be installed just like any package using the dotnet CLI:\n```sh\ndotnet add package Blokyk.CA2254CodeFix\n```\n\nYou can also reference it in your project:\n```xml\n\u003cPackageReference Include=\"Blokyk.CA2254CodeFix\" Version=\"*\" /\u003e\n```\n\n## Details about the expression names\n\nThe expressions in the interpolated string need to be replaced with *something*,\nso obviously this codefix is quite opinionated. Here are some examples of\ntransformations used to derive the names:\n\n| expression            | resulting name     |\n|-----------------------|--------------------|\n| `foo.bar`             | `Bar`              |\n| `foo.bar()`           | `Bar`              |\n| `foo.bar(alice, bob)` | `BarOfALiceAndBob` |\n| `foo is not null`     | `FooIsNotNull`     |\n| `DateTime.UtcNow`     | `DateTime`         |\n\nThe actual derivation is mostly done in [`ExpressionNamer.cs`](./ExpressionNamer.cs),\nwith a little bit more in [`CSharpLoggerMessageFixer.cs`](./CSharpLoggerMessageFixer.cs)\nright now.\n\nIf you'd like to suggest a tweak or a new naming rule, don't hesitate to open a\nnew issue or PR, I'm completely open to ideas on this!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblokyk%2Fca2254-codefix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblokyk%2Fca2254-codefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblokyk%2Fca2254-codefix/lists"}