Skip to content

ZeroLog v2#44

Merged
ltrzesniewski merged 120 commits intomasterfrom
v2
Mar 29, 2022
Merged

ZeroLog v2#44
ltrzesniewski merged 120 commits intomasterfrom
v2

Conversation

@ltrzesniewski
Copy link
Member

@ltrzesniewski ltrzesniewski commented Jan 10, 2022

I've been working on a v2 of ZeroLog, and I'm currently in that weird no-man's land where I'm not sure if I changed too much or not enough... I's clearly not finished, but I'd like to have your input @rbouallou @MendelMonteiro @rverdier @farnyser about the new design.

Here are the main changes:

General

  • ZeroLog now targets .NET 6 only. A netstandard2.0 target needs to be added, which would only allow logging (no appenders, no config, etc).

Loggers

  • InfoFormat (etc) methods have been removed, they are replaced by the new interpolated string handlers feature of C# 10 😍, which means the following code:
    _log.Info($"Hello {World()}!");
    is equivalent to:
    if (_log.IsInfoEnabled)
    {
        _log.Info().Append("Hello ").Append(World()).Append("!").Log();
    }
  • The ILogEvent interface has been removed, it's replaced by the LogMessage class, in order to remove lots of interface calls.
  • The ILog interface has been removed, it's replaced by the Log class, for the same reason. It made sense to have a Log/LogMessage pair of classes. There is now a single implementation instead of 3.
  • Calling LogManager.GetLogger before the LogManager is initialized will return a Log object which will work as soon as the log manager is initialized (it previously returned a no-op object which could never work).
  • LogEventArgumentExhaustionStrategy has been removed. We now always truncate (it didn't work if the buffer was exceeded previously anyway).

Appenders

  • I added a FormattedLogMessage class which represents a formatted message (the logic was in LogManager previously). The IAppender API has been changed to account of this.
  • StringFormatter has been removed. The library now uses the built-in features of .NET 6 (ISpanFormattable) that let us format values into a Span<char>. That one required a lot of changes... 😰
  • Appenders can now each have a different encoding (makes sense for file vs console for instance).
  • The library now allocates a large buffer that will never be extended during formatting (max line size = 16k chars).

TODO

  • Validate the new design (this PR)
  • Add a limited netstandard2.0 target (logging only)
  • I'd like to remove the JSON config, and replace it with something in the code. Also remove the JSON.NET library (a logging library should have no dependencies if possible).
  • Appender construction could be better handled (we now supply every parameter separately to the constructor, which makes adding new parameters a breaking change).
  • Optimization/benchmarking
  • Add more unit tests
  • There are still a few TODO comments in the source code
  • Truncation support is incomplete right now (it won't truncate value types if string capacity is exceeded)
  • Add an interpolated string handler overload to handle .Append($"...")
  • DateOnly/TimeOnly
  • Ensure a message is not enqueued multiple times
  • Strong name
  • Update the readme file
  • XML documentation
  • Test helpers
  • Abstract formatting (to support logfmt for instance)

ltrzesniewski and others added 6 commits March 1, 2022 15:46
This lets users define an extension method on their objects that returns an append operation. This is a way to support unknown objects in interpolated strings.
@ltrzesniewski ltrzesniewski marked this pull request as ready for review March 18, 2022 14:22
@ltrzesniewski ltrzesniewski requested a review from rverdier March 18, 2022 14:22
@ltrzesniewski ltrzesniewski merged commit e607d1d into master Mar 29, 2022
@ltrzesniewski ltrzesniewski deleted the v2 branch March 29, 2022 13:24
@ltrzesniewski ltrzesniewski added this to the v2.0 milestone May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants