LogFusionX 0.1.4

dotnet add package LogFusionX --version 0.1.4                
NuGet\Install-Package LogFusionX -Version 0.1.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LogFusionX" Version="0.1.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LogFusionX --version 0.1.4                
#r "nuget: LogFusionX, 0.1.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LogFusionX as a Cake Addin
#addin nuget:?package=LogFusionX&version=0.1.4

// Install LogFusionX as a Cake Tool
#tool nuget:?package=LogFusionX&version=0.1.4                

LogFusionX

LogFusionX is a powerful logging library designed to handle different log levels, formats, and logging scenarios. It provides synchronous logging capabilities, including the ability to log to files, handle exceptions, and log warning and error messages in a straightforward manner.

Installation

To install LogFusionX, use the following command:

dotnet add package LogFusionX --version 0.1.4

This will add the latest version of LogFusionX to your project.

Usage

To use LogFusionX for logging, you can follow the example below:

Example Code

using System;
using System.IO;
using LogFusionX.Core.Configurations;
using LogFusionX.Core.Loggers;

class Program
{
    static void Main(string[] args)
    {
        // Set up the logger configuration
        var options = new XLoggerConfigurationOptions
        {
            LogDirectory = Directory.GetCurrentDirectory() + "/AppData", // Log file directory
            LogFileName = "FusionLogs" // Log file name
        };

        // Initialize the logger with the configuration options
        var logger = new FusionXLogger(options);

        try
        {
            for (int i = 0; i < 10; i++)
            {
                // Log info messages
                if (i == 0)
                {
                    logger.Log($"Hello, this is a sync log message {i} - {DateTime.Now}, by LogFusionX");
                }
                // Log warning messages
                else if (i == 1)
                {
                    logger.LogWarning("Hi, this is a warning message", new Exception("Warning exception"));
                }
                // Simulate an error
                else
                {
                    throw new Exception("Simulated error");
                }
            }
        }
        catch (Exception ex)
        {
            // Log error messages with exception details
            logger.LogError("An error occurred while processing the loop. Please try again later.", ex);
        }

        // Synchronous Logging
        //logger.WriteLog("This is a synchronous log entry.");

        Console.WriteLine("Logs written. Press any key to exit...");
        Console.ReadKey();
    }
}

Explanation:

Logger Configuration

The XLoggerConfigurationOptions class is used to configure the logger in LogFusionX. Key properties include:

  • LogDirectory: Specifies the directory where log files will be stored.
  • LogFileName: Allows you to set a custom name for the log file. Default names can follow a date-based pattern for easy organization.
  • EnableConsoleLogging: Enables or disables logging to the console for debugging or local development.
  • MaxLogFileSize: Defines the maximum size of a log file before it rolls over to a new file.

Example configuration:

var config = new XLoggerConfigurationOptions
{
    LogDirectory = "C:\\Logs",
    LogFileName = "AppLogs.log",
    EnableConsoleLogging = true,
    MaxLogFileSize = 5 * 1024 * 1024 // 5 MB
};

Logging Levels in LogFusionX

LogFusionX supports a wide range of logging levels to handle different types of application scenarios effectively:

1. Info

Logs general information, such as application startup, process completion, or routine activities.

Example:

"Application started successfully at 12:30 PM"

2. Warning

Logs potential issues or unexpected behavior that does not stop the application but needs attention.

Example:

"Memory usage exceeded 80%, consider optimizing"

3. Error

Logs application errors, such as unhandled exceptions or invalid operations. Includes details about the exception (e.g., stack trace).

Example:

"Database connection failed: TimeoutException at ..."

4. Trace

Logs detailed, step-by-step execution for debugging purposes, useful during development or troubleshooting.

Example:

"Entering method ProcessOrder at 12:31:05 PM"

5. Fatal

Logs critical failures that cause the application to crash or become unusable. Typically used for catastrophic events.

Example:

"System crash: OutOfMemoryException - shutting down"

6. Performance

Logs performance-related metrics to monitor response times or identify bottlenecks in the application.

Example:

"API response time: 350ms for /getOrderDetails"

7. Security

Logs security-related events, such as failed authentication attempts, unauthorized access, or policy violations.

Example:

"Unauthorized access attempt detected: IP 192.168.1.101"

8. Custom (Extendable)

LogFusionX allows defining custom log levels tailored to specific organizational needs. Examples include:

  • Audit: Tracks user actions or data modifications for compliance.
  • Critical: Highlights issues that may not crash the application but need immediate attention.

Example:

"User JohnDoe updated record #1234 at 2:15 PM."

Exception Handling

If an exception occurs during logging, it is caught and logged using LogError.

Synchronous Logging

LogFusionX allows synchronous logging, ensuring that messages are written in the correct sequence.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to fork the repository, submit issues, or make pull requests to contribute to the development of LogFusionX.

Repository

You can find the project repository and source code here:
LogFusionX GitHub Repository


Thank you for using LogFusionX! 🎉

We hope this library makes logging in your .NET projects more powerful and easier. If you have any feedback, questions, or suggestions, feel free to reach out. Stay tuned for more features and updates in the future!

Happy Coding! 🚀

Product 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.4 75 12/20/2024
0.1.3 71 12/20/2024
0.1.2 72 12/19/2024
0.1.1 74 12/18/2024
0.1.0 69 12/18/2024

Initial release of LogFusionX package for enhanced logging functionality.