Same output, less pain — reimplementing the LoggerMessage generator. #118138
Unanswered
h-shahzaib
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks 👋
So I recently tried reimplementing the
LoggerMessage
-based source generator from Microsoft.Extensions.Logging — not to change the actual behavior, but just to explore a different structure that’s a bit easier to work with.The original implementation is super optimized and works fine as-is — but honestly, it's kinda hard to follow in places. You've got a lot of manual indentation tracking, raw strings with spacing baked in, and logic that's all tangled up with formatting.
I ended up rebuilding the whole thing using a small library I’ve been working on called Nest. It's basically a lightweight abstraction over
StringBuilder
for structured text/code generation — helps with nesting, indentation, conditionals etc. without needing to juggle these directly.Anyway, here’s the repo:
🔗 NestVsMsLogger
This includes both:
StringBuilder
)Both produce identical output (aside from maybe a few newlines or spaces). You can check the
Output/
folder and tests for that.Why I'm sharing this:
Not proposing we change anything right now — this is more of an experiment. Just wondering if there's room to discuss whether using a more composable/text-builder style approach would help make these kinds of generators easier to reason about or maintain long-term.
Things like:
Would love to hear thoughts — even if it's just "nah, not worth it." I'm curious what others think of this kind of setup.
Thanks for reading, and also just — thanks for the incredible work on this whole ecosystem. ❤️
Beta Was this translation helpful? Give feedback.
All reactions