Hexa.NET.Logging
2.0.0
dotnet add package Hexa.NET.Logging --version 2.0.0
NuGet\Install-Package Hexa.NET.Logging -Version 2.0.0
<PackageReference Include="Hexa.NET.Logging" Version="2.0.0" />
paket add Hexa.NET.Logging --version 2.0.0
#r "nuget: Hexa.NET.Logging, 2.0.0"
// Install Hexa.NET.Logging as a Cake Addin #addin nuget:?package=Hexa.NET.Logging&version=2.0.0 // Install Hexa.NET.Logging as a Cake Tool #tool nuget:?package=Hexa.NET.Logging&version=2.0.0
Hexa.NET.Logging
Overview
Hexa.NET.Logging is a small, efficient logging framework for .NET applications. It provides a simple API for logging messages at various levels (e.g., error, warning, information). This framework is designed to be lightweight and easy to integrate into your existing .NET applications.
Features
- Lightweight and efficient logging.
- Easy-to-use API.
- Support for multiple logging levels.
- Ability to cache loggers for improved performance.
- Exception logging support.
- Conditional logging support.
- Async logging support.
Installation
To install Hexa.NET.Logging, add the following package to your project:
dotnet add package Hexa.NET.Logging
Usage
Here is a basic example of how to use Hexa.NET.Logging in your application:
- Getting a Logger:
using Hexa.NET.Logging;
// Retrieve a logger for a specific category
var logger = LoggerFactory.GetLogger(nameof(MyClass));
// Store the logger in a static field/property for better performance
private static readonly ILogger _logger = LoggerFactory.GetLogger(nameof(MyClass));
- Logging Messages:
// Log an error message
_logger.Error("Failed to create input layout, signature was null.");
// Log a warning message
_logger.Warning("This is a warning message.");
// Log an informational message
_logger.Info("This is an informational message.");
- Logging Exceptions:
try
{
// Your code here
}
catch (Exception ex)
{
_logger.Log(ex); // Log the exception
}
- Conditional Logging:
// Log a message only if a condition is met
_logger.WarnIf(foo == bar, "This is a warning message.");
- Example in a Class:
using Hexa.NET.Logging;
public class MyClass
{
private static readonly ILogger _logger = LoggerFactory.GetLogger(nameof(MyClass));
public void SomeMethod()
{
_logger.Info("This is an informational message.");
try
{
// Your code here
}
catch (Exception ex)
{
_logger.Log(ex); // Log the exception
}
}
}
Logging Levels
Hexa.NET.Logging supports the following logging levels:
- Critical: Use for logging critical messages that indicate a critical failure in the application.
- Error: Use for logging error messages that indicate a failure in the application.
- Warning: Use for logging warning messages that indicate a potential issue or important information.
- Info: Use for logging informational messages that highlight the progress of the application.
- Debug: Use for logging debug messages that provide detailed information for debugging purposes.
- Trace: Use for logging trace messages that provide detailed information for tracing purposes.
Best Practices
- Cache Loggers: Store the ILogger instances in static fields or properties to avoid retrieving the logger multiple times, which can improve performance.
- Use Appropriate Logging Levels: Use the correct logging level to ensure that the log output is meaningful and easy to understand.
- Log Exceptions: Use the Log(Exception ex) method to log exceptions and capture stack trace information.
- Conditional Logging: Use conditional logging methods to log messages based on specific conditions.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure that your code follows the project's coding standards and includes appropriate tests.
License
Hexa.NET.Logging is licensed under the MIT License. See the LICENSE file for more details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Hexa.NET.Utilities (>= 2.0.1)
-
net8.0
- Hexa.NET.Utilities (>= 2.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Hexa.NET.Logging:
Package | Downloads |
---|---|
Hexa.NET.KittyUI
A Cross-Platform UI-Framework build upon ImGui, simplifying ImGui management in C#. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 374 | 7/27/2024 |