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:
- GitHub: Spargine 10
- NuGet: dotNetDaveNuGet
FastLogger
The FastLogger type in Spargine provides developers with an efficient way to log messages to the project’s logging framework. By utilizing the LoggerMessageAttribute and code generation, FastLogger ensures messages are logged at maximum speed without sacrificing clarity or functionality.
Logging with an ILogger object is now as simple as the following example:
FastLogger.LogCritical(logger: this._logger,
message: “Something bad happened!”,
ex: ex);
Performance Boost
Benchmark reports demonstrate a significant performance improvement when using FastLogger over traditional logging methods—FastLogger achieves an 11x increase in overall speed!
Enhanced Logging Methods for ILogger
Effective logging is crucial for diagnosing and debugging applications. The following extension methods for ILogger 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 Logging
- LogCritical(ILogger logger, string message, Exception exception)
Logs a critical-level message along with an exception.
EventId: 912, EventName: CRITICAL - LogError(ILogger logger, string message)
Logs an error message.
EventId: 301, EventName: ERROR - LogException(ILogger logger, string message, Exception exception)
Logs an exception message, providing details about the exception.
EventId: 501, EventName: EXCEPTION
Debugging and Trace Logging
- LogDebug(ILogger logger, string message)
Logs a debug-level message to help with troubleshooting.
EventId: 201, EventName: DEBUG - LogTrace(ILogger logger, string message)
Logs a trace-level message, useful for granular debugging.
EventId: 101, EventName: TRACE
Informational and Warning Messages
- LogInformation(ILogger logger, string message)
Logs an informational message.
EventId: 401, EventName: INFORMATION - LogWarning(ILogger logger, string message)
Logs a warning message to indicate potential issues.
EventId: 601, EventName: WARNING
These methods help standardize logging practices and improve traceability, making it easier to diagnose and monitor application behavior.
Future-Proof Logging
One of the key benefits of using FastLogger is its adaptability. If a faster logging method is discovered, FastLogger will be updated accordingly, so you can enjoy improved performance without needing to modify your project’s code.
Summary
I am confident that these enhanced methods in Spargine will greatly benefit your projects by improving performance and reliability. Detailed benchmark results are available on GitHub. The success of open-source projects like Spargine depends significantly on community involvement. If you find these updates useful or have ideas for further improvements, I encourage you to contribute. Whether by submitting a pull request, reporting issues, or suggesting new features, your input is invaluable.
Together, we can continue to make Spargine a powerful and essential tool for the .NET community. Your feedback and suggestions are highly appreciated, so please share them in the comments section.
If you are interested in contributing to this project or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!
Thank you for your support, and happy coding!
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf 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.


