Mazzlog 1.0.1

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

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

Mazzlog

.NET Core ILogger implementation with storage on your hands

How to use

  • After your CreateDefaultBuilder call, include the ConfigureLogging extension method to add the Mazzlogger provider
  • Create a configuration class that extends from IConfigureMazzLogger
  • At D.I. container setup, on ConfigureServices, call ConfigureMazzlog with your configuration class
  • Run your code

Show me the code

In your Program class:

Host.CreateDefaultBuilder(args)
    .ConfigureLogging(logging =>
    {
        logging.ClearProviders(); // Optionally
        logging.AddMazzlog(c =>
        {
            // Optionally settings
            c.DefaultPropertyScopes = new Dictionary<string, object>() 
            {
                { "app-name", "AppX" },
                { "app-instance", "Instance001" },
            };

            c.DeniedCategories = new List<string> { "Microsoft.Hosting.Lifetime" };
        });
    });
    

The configuration class:

public sealed class MyLoggerConfiguration : IConfigureMazzLogger
{
    public TimeSpan FlushInterval => TimeSpan.FromSeconds(5);
    public uint ItensPerFlush => 10;

    // What do you want to do with your logs? You code go here
    public async Task OnFlushAsync(IReadOnlyCollection<LogEntry> logs)
    {
        using var txt = File.Open("logs.txt", FileMode.Append, FileAccess.Write);
        using var writter = new StreamWriter(txt);
        var sb = new StringBuilder();

        foreach (var log in logs)
        {
            sb.Append(JsonSerializer.Serialize(log));
            sb.Append(Environment.NewLine);
        }
        
        // Save my logs in a txt file
        await writter.WriteAsync(sb.ToString());
    }
}

In your Startup class:

public void ConfigureServices(IServiceCollection services)
{
    services.ConfigureMazzlog<MyLoggerConfiguration>();
}

Log usage recommendation:

Mazzlog is asynchronous and use concurrency logic to work with your logs, this means that the logs ordering is not guaranteed, so, we encourage the use of scopes to get around this problem

public class HomeController : Controller
{
    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
    }
    
    private readonly ILogger<HomeController> _logger;
    
    public IActionResult Index()
    {
        using (_logger.BeginScope("RequestId", Guid.NewGuid().ToString()))
        using (_logger.BeginScope(nameof(Index)))            
        {
            return Foo();
        }
    }
    
    private IActionResult Foo()
    {
        using (_logger.BeginScope(nameof(Foo)))
        {
            _logger.LogInformation("Hello World!");
            return Ok();
        }
    }
}

Enjoy =)

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

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 466 2/11/2020
1.0.0 449 2/11/2020