Posts tagged "source-generators"

LoggerMessage Part 2: Instance Methods and Automatic Exception Handling

In the previous article we explored how the LoggerMessage attribute uses source generators to create high-performance logging code via static extension methods. That approach works great for shared log methods, but it requires you to pass the ILogger instance on every call. In this follow-up we'll look at two features that reduce boilerplate even further: non-static partial methods that access the logger from the primary constructor, and automatic exception recognition.

Supercharge Your .NET Logging Performance with LoggerMessage Attribute

Logging is essential for monitoring and debugging applications, but it can become a performance bottleneck when not implemented efficiently. The LoggerMessage attribute, introduced in .NET 6, offers a powerful solution that combines high performance with developer-friendly APIs. In this article, we'll explore how this attribute reduces logging overhead, handles exceptions gracefully, and leverages source generators to create optimized code.