Maniceraf.SimpleMongoDbLogger 1.0.1

dotnet add package Maniceraf.SimpleMongoDbLogger --version 1.0.1                
NuGet\Install-Package Maniceraf.SimpleMongoDbLogger -Version 1.0.1                
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="Maniceraf.SimpleMongoDbLogger" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Maniceraf.SimpleMongoDbLogger --version 1.0.1                
#r "nuget: Maniceraf.SimpleMongoDbLogger, 1.0.1"                
#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 Maniceraf.SimpleMongoDbLogger as a Cake Addin
#addin nuget:?package=Maniceraf.SimpleMongoDbLogger&version=1.0.1

// Install Maniceraf.SimpleMongoDbLogger as a Cake Tool
#tool nuget:?package=Maniceraf.SimpleMongoDbLogger&version=1.0.1                

Maniceraf.SimpleMongoDbLogger - MongoDB Logger for .NET

Maniceraf.SimpleMongoDbLogger is a versatile logging library that seamlessly integrates with MongoDB, providing developers with an efficient means to log messages of various severity levels directly into a MongoDB database.

Getting Started

To begin using Maniceraf.SimpleMongoDbLogger start by installing the latest version of the package from Nuget.

Installation

You can install the Maniceraf.SimpleMongoDbLogger via NuGet. Use the Package Manager Console or the .NET CLI:

dotnet add package Maniceraf.SimpleMongoDbLogger --version 1.0.1

Usage

Initialization

Initialize the logger by providing the MongoDB connection string, database name, and collection name:

using Maniceraf.SimpleMongoDbLogger;

class Program
{
    static void Main(string[] args)
    {
        string connectionString = "...";
        string databaseName = "...";
        string collectionName = "...";

        var logger = new MongoDbLogger(connectionString, databaseName, collectionName);

        // Log some messages
        logger.WriteLog(LogLevel.Info, "This is an informational message");
        logger.WriteLog(LogLevel.Warning, "This is a warning message");
        logger.WriteLog(LogLevel.Error, "This is an error message");

        await logger.WriteLogAsync(LogLevel.Info, "This is an informational message");
        await logger.WriteLogAsync(LogLevel.Warning, "This is a warning message");
        await logger.WriteLogAsync(LogLevel.Error, "This is an error message");
    }
}

Dependency Injection

If you prefer using Dependency Injection:

1. Configure the MongoDB connection in your application's Startup.cs or equivalent:
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
using MongoDBLogger;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // MongoDB configuration
        string connectionString = "...";
        string databaseName = "...";
        string collectionName = "...";

        // Register MongoDBLogger as a service
        services.AddSimpleMongoDbLogger(options =>
        {
            options.ConnectionString = connectionString;
            options.DatabaseName = databaseName;
            options.CollectionName = collectionName;
        });

        // Or register MongoDBLogger with another way
        services.AddSimpleMongoDbLogger(connectionString, databaseName, collectionName);

        // Other service registrations...
    }
}
2. Inject the ILogger interface where logging is needed:
using MongoDBLogger;

public class SomeClass
{
    private readonly IMongoDbLogger _logger;

    public SomeClass(IMongoDbLogger logger)
    {
        _logger = logger;
    }

    public void SomeMethod()
    {
        // Log some messages
        logger.WriteLog(LogLevel.Info, "This is an informational message");
        await logger.WriteLogAsync(LogLevel.Info, "This is an informational message");

        // Logging other messages...
    }
}

License

This library is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.1 196 12/4/2023
1.0.0 105 12/3/2023
1.0.0-preview-1 101 12/3/2023