Skip to content

Releases: Abc-Arbitrage/ZeroLog

v2.6.1

12 Feb 18:23

Choose a tag to compare

New features

Improved support of ANSI color codes in log patterns

  • Added a %{color:...} placeholder which defines the color to use in its format string.

    The %{color:...} placeholder can be used to set the color of the following text in a terminal by emitting SGR ANSI codes.
    The format string of this placeholder can contain multiple comma- or semicolon-separated values which specify the attributes of the emitted ANSI code. Color definitions are defined in a single value.

    Supported values include:

    Type Examples
    Attribute reset, bold, italic
    Standard color red, blue, green
    Color target foreground (default), background, fg, bg
    Color intensity dark (default), bright followed by a standard color
    Custom color #FFA0A0
    Default color default foreground
    Custom code 94 (bright blue foreground)

    A full example would be: %{color:reset, bold, bright white foreground, #2A3B4C background}.

v2.6.0

12 Jan 19:12

Choose a tag to compare

New features

Improved support of ANSI color codes in log patterns

  • ConsoleAppender becomes a simple implementation of StreamAppender:
    • Color output now uses ANSI codes on Windows
    • Coloring becomes customizable through the given Formatter or DefaultStyle (see below)
  • Better SGR codes support in PatternWriter and DefaultFormatter:
    • New placeholders:
      • %levelColor: configurable through the LogLevelColors property
      • %resetColor: an alias for \e[0m
    • The strings in the pattern, the LogLevels and LogLevelColors properties all support custom SGR codes
    • The %{column:n} placeholder now counts by grapheme clusters
  • Added a few example styles in the DefaultStyle class which can be supplied to the ConsoleAppender constructor
    • Current default style for ConsoleAppender: DefaultStyle.Colored.BlueAndWhite (or its plain text version if ColorOutput is false)
    • Current default style for DefaultFormatter: DefaultStyle.NoColor.Simple
    • See the ZeroLog.Examples project or cat the examples.txt file from the artifacts in a console for a preview
  • New APIs:
    • DefaultFormatter.MessagePatternWriter to configure colors in the pattern
    • WithoutAnsiColorCodes() in PatternWriter and DefaultFormatter to return a version without color codes
    • Appender.Initialize() which is called before an appender is first used
    • StreamAppender.Formatter changes from init to set
    • New constructors in ConsoleAppender and DefaultFormatter

Analyzers and code fixes

  • Added a code fix which lets you change from the simple syntax (_log.Info(...)) to Append syntax (_log.Info().Append(...).Log()).
    This is particularly useful if you want to add structured data to a log message:
    imageimage

  • Renamed "Use string interpolation" to "Use simple syntax" for consistency. This undoes the previous fix:
    imageimage

  • Added a [PatternWriter.Pattern] attribute to analyze a literal pattern string on custom string arguments and properties

v2.5.0

05 Dec 14:11

Choose a tag to compare

New features

This release focuses on easier writing of custom formatters:

  • Added LoggedMessage.LoggerCompactName
  • Added overloads to Formatter.Write and Formatter.PadToColumn
  • Added PatternWriter, which implements pattern usage, such as in DefaultFormatter.PrefixPattern
  • Added %message, %exceptionType and %exceptionMessage placeholders

v2.4.0

27 Nov 13:50

Choose a tag to compare

New features

  • Added AOT support (#70)
  • Added LoggedMessage.CreateTestMessage
  • Added %threadId and %threadName placeholders (#69)

v2.3.0

14 Aug 09:39

Choose a tag to compare

New features

  • Added a net9.0 target which adds where T : allows ref struct to LogManager.GetLogger<T>()
  • Added %% to prefix patterns which outputs a single % character
  • Added ZeroLogConfiguration.LoggingThreadInitializer which allows customization of the background logging thread, mainly for thread affinity or priority (#68)

v2.2.0

26 Jul 16:04

Choose a tag to compare

New features

  • Added a LogManager.Flush method, which can be useful in benchmarks
  • Added custom TimeProvider support in the configuration (#62, requires .NET 8)
  • Added %localDate and %localTime placeholders (#64)

Fixes

  • Fixed LogManager.RegisterAllEnumsFrom to be safe to use with assemblies containing invalid types
  • Fixed enum support on .NET 6 under Linux

v2.1.1

11 Oct 15:13

Choose a tag to compare

  • Fixed a race condition on shutdown where the last messages could be skipped

v2.1.0

09 Feb 17:19

Choose a tag to compare

Formatting

  • Formattable prefix placeholders with the %{type:format} syntax, e.g. %{date:yyyy-MM-dd HH:mm:ss}
    • An integer format can be used on string placeholders to specify a minimum field length, e.g. %{logger:40}
    • %{level:pad} can be used to make log levels a constant length (alias for %{level:5})
  • New prefix placeholders:
    • %newline inserts a system-dependent newline
    • %{column:N} inserts padding until the column index N is reached
    • %loggerCompact inserts the logger name with a shortened namespace, e.g. Foo.Bar.Baz => FB.Baz
  • New Roslyn analyzer which validates constant prefix patterns at build-time
  • Added TextWriterAppender (use TextWriterAppender(Console.Out) in unit tests)
  • New APIs in LoggedKeyValue: ValueType, TryGetValue<T>

Unit testing

  • Added ZeroLogConfiguration CreateTestConfiguration() with suitable defaults for unit testing
  • Support for a synchronous appending strategy (on the current thread) for use in unit tests (AppendingStrategy setting)
  • Added LoggedMessage.Clone() to capture logged messages
  • Snapshot testing with Verify.ZeroLog

Configuration

  • Added new convenience APIs for configuration:
    • ZeroLogConfiguration.SetLogLevel
    • New LoggerConfiguration constructor overloads
    • New initializer syntax for adding Loggers to the collection: Loggers = { { NameA, LevelA }, { NameB, LevelB } }
  • Made the UseBackgroundThread setting obsolete: the worker thread is now always a background thread
  • Added a LogManager.Configuration property

Various

  • Added a pool exhaustion strategy which is allowed to allocate
  • Added support for DateTimeOffset
  • Don't flood "Pool exhausted" messages
  • Various optimizations and bug fixes

v2.0.1

16 Dec 09:41

Choose a tag to compare

  • Added an option to use a background thread for appender execution (#58 by @Donis-)
  • Added a net7.0 target (#47)

v2.0.0

03 Aug 13:11

Choose a tag to compare

Rewrite for .NET 6

ZeroLog has been entirely rewritten to take advantage of new APIs in .NET 6 and new features of C# 10. Therefore, v2 only works on .NET 6 and above. A .NET Standard 2.0 target is provided to enable logging from libraries, but the main project needs to target .NET 6.

The surface API has been redesigned, but migration from v1 should still be straightforward (even though repetitive work is required).

See the readme file for more detailed information, and #44 for implementation notes.

Major changes

  • InfoFormat (and similar) 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 now 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 slower interface calls.
  • The ILog interface has been removed, it's replaced by the Log class, for the same reason.
  • Appenders have been entirely redesinged, and the StringFormatter library has been replaced with built-in .NET 6 formatting features.
  • ASCII values have been replaced with UTF-8.
  • External JSON configuration has been removed. The library is now configured in code. Live configuration updates are possible (but allocate).
  • The library now includes Roslyn analyzers that check for correct usage, and a new code fix for migration to the new syntax. See #45.