Boost Your .NET Projects: Maximize Your .NET Performance with Spargine FastLoggerExtensions

Spargine is a collection of open-source assemblies and NuGet packages designed for .NET 10, which I have been developing and maintaining since the release of .NET Framework 2. These assemblies are not only a core part of my projects but are also actively deployed in production environments across several companies I collaborate with.

Get Spargine

You can access the source code and NuGet packages here:

This documentation covers the FastLoggerExtensions class within the DotNetTips.Spargine.8.Core project.

FastLoggerExtensions: High-Performance Logging for .NET

The FastLoggerExtensions type in Spargine provides developers with an optimized way to log messages using the built-in .NET logging framework. By leveraging LoggerMessageAttribute and source code generation, FastLoggerExtensions ensures logging is performed at maximum speed without compromising clarity or functionality.

Logging with an ILogger object is now as simple as the following example:

this._logger.LogExceptionMessage(message: "Could not load files", exception: exception);

Performance Boost

Benchmark reports demonstrate a significant performance improvement when using FastLoggerExtensions over traditional logging methods—achieving an average 10x increase in speed!

Enhanced Logging Methods for ILogger

Effective logging is essential for diagnosing and debugging applications. The following ILogger extension methods provide structured logging at different severity levels, ensuring consistent and informative log entries. Each method automatically includes the calling method’s name as part of the logged message.

Critical and Error

  • LogCriticalMessage(this ILogger logger, string message, Exception exception) – Logs a critical-level message along with an exception. EventId: 911, EventName: CRITICAL
  • LogErrorMessage(this ILogger logger, string message) – Logs an error message. EventId: 300, EventName: ERROR
  • LogExceptionMessage(this ILogger logger, string message, Exception exception) – Logs an exception message, providing details about the exception. EventId: 500, EventName: EXCEPTION

Debugging and Trace

  • LogDebugMessage(this ILogger logger, string message) – Logs a debug-level message for troubleshooting. EventId: 200, EventName: DEBUG
  • LogTraceMessage(this ILogger logger, string message) – Logs a trace-level message for detailed debugging. EventId: 100, EventName: TRACE

Informational and Warning

  • LogInformationMessage(this ILogger logger, string message) – Logs an informational message. EventId: 400, EventName: INFORMATION
  • LogWarningMessage(this ILogger logger, string message) – Logs a warning message to indicate potential issues. EventId: 600, EventName: WARNING

Logging for Stored Procedures

  • LogStoredProcedureError(this ILogger logger, string storedProcedure, string message) – Logs a stored procedure error. EventId: 700, EventName: ERROR
  • LogStoredProcedureNoRecordsFound(this ILogger logger, string storedProcedure) – Logs when a stored procedure returns no records. EventId: 701, EventName: WARNING

These methods help standardize logging practices, improve traceability, and simplify application monitoring.

Summary

The FastLoggerExtensions in Spargine, significantly enhance logging performance and reliability. Detailed benchmark results are available on GitHub, showcasing the improvements these extensions bring to .NET applications.

Get Involved!

The success of open-source projects like Spargine relies on community contributions. If you find these updates useful or have ideas for further improvements, I encourage you to contribute by:

  • Submitting pull requests
  • Reporting issues
  • Suggesting new features

Your input is invaluable in making Spargine an even more powerful tool for the .NET community.

If you are interested in contributing or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!

Thank you, and happy coding!

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.