Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.25k stars 88 forks source link

Update ZLoggerOptions/ provider setup apis #111

Closed hadashiA closed 10 months ago

hadashiA commented 10 months ago

EDIT:

Add the AddZLogger(...) method to consolidate multiple provider declarations for ZLogger.

 logging.AddZLogger(zLogger =>
{
    zLogger.AddConsole(options =>
    {
        options.OutputEncodingToUtf8 = true;
        options.ConfigureEnableAnsiEscapeCode = false;
        options.UsePlainTextFormatter(formatter =>
        {
            formatter.SetPrefixFormatter($"{0} [{1}]", (template, info) => template.Format(info.Timestamp, info.LogLevel));
        });
    });

    zLogger.AddFile("/path/to/file", options => 
    {
        options.IncludeScopes = true;
        options.FlushRate = TimeSpan.Zero;
        options.UseJsonFormatter());
    });
});

And update ZLoggerOptions:

hadashiA commented 10 months ago