LoggerMessage: Why So Difficult? #110364
Unanswered
stbychkov
asked this question in
Show and tell
Replies: 1 comment 2 replies
-
This is very cool use of interceptors! I think the only downside to this approach is that you don't get to treat the log message like a contract (the log level and the event id are not coupled to the logger message, but instead reverse engineered from the call site). If you wanted to make sure that log messages were versioned with similar rigor to public API how would you go about doing it with this approach? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys,
I've created a source generator (NuGet package) to automate the creation of
LoggerMessage
calls in.NET
projects. After dealing with too much boilerplate using your approach, I built this solution to generate everything automatically with minimal setup from the user.Problem
Writing repetitive boilerplate code for every log statement is tedious, especially in larger projects with thousands of log calls.
Solution
My solution scans the entire codebase and automatically generates logging methods for all log calls, requiring no additional attributes or manual method creation. It works quite fast even in midsize projects with over 2k+ log statements. For very large projects, further optimization can be explored.
Conclusion
I believe this approach is more user-friendly, as it keeps the same interaction with the
ILogger
class and eliminates the need for redundant method definitions. I hope you find this approach valuable and would consider adding it to the core. If you'd like help with contributing, feel free to reach out to me.Beta Was this translation helpful? Give feedback.
All reactions