Releases: Abc-Arbitrage/ZeroLog
v2.6.1
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,italicStandard color red,blue,greenColor target foreground(default),background,fg,bgColor intensity dark(default),brightfollowed by a standard colorCustom color #FFA0A0Default color default foregroundCustom code 94(bright blue foreground)A full example would be:
%{color:reset, bold, bright white foreground, #2A3B4C background}.
v2.6.0
New features
Improved support of ANSI color codes in log patterns
ConsoleAppenderbecomes a simple implementation ofStreamAppender:- Color output now uses ANSI codes on Windows
- Coloring becomes customizable through the given
FormatterorDefaultStyle(see below)
- Better SGR codes support in
PatternWriterandDefaultFormatter:- New placeholders:
%levelColor: configurable through theLogLevelColorsproperty%resetColor: an alias for\e[0m
- The strings in the pattern, the
LogLevelsandLogLevelColorsproperties all support custom SGR codes - The
%{column:n}placeholder now counts by grapheme clusters
- New placeholders:
- Added a few example styles in the
DefaultStyleclass which can be supplied to theConsoleAppenderconstructor- Current default style for
ConsoleAppender:DefaultStyle.Colored.BlueAndWhite(or its plain text version ifColorOutputis false) - Current default style for
DefaultFormatter:DefaultStyle.NoColor.Simple - See the
ZeroLog.Examplesproject orcattheexamples.txtfile from the artifacts in a console for a preview
- Current default style for
- New APIs:
DefaultFormatter.MessagePatternWriterto configure colors in the patternWithoutAnsiColorCodes()inPatternWriterandDefaultFormatterto return a version without color codesAppender.Initialize()which is called before an appender is first usedStreamAppender.Formatterchanges frominittoset- New constructors in
ConsoleAppenderandDefaultFormatter
Analyzers and code fixes
-
Added a code fix which lets you change from the simple syntax (
_log.Info(...)) toAppendsyntax (_log.Info().Append(...).Log()).
This is particularly useful if you want to add structured data to a log message:


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


-
Added a
[PatternWriter.Pattern]attribute to analyze a literal pattern string on customstringarguments and properties
v2.5.0
New features
This release focuses on easier writing of custom formatters:
- Added
LoggedMessage.LoggerCompactName - Added overloads to
Formatter.WriteandFormatter.PadToColumn - Added
PatternWriter, which implements pattern usage, such as inDefaultFormatter.PrefixPattern - Added
%message,%exceptionTypeand%exceptionMessageplaceholders
v2.4.0
v2.3.0
New features
- Added a
net9.0target which addswhere T : allows ref structtoLogManager.GetLogger<T>() - Added
%%to prefix patterns which outputs a single%character - Added
ZeroLogConfiguration.LoggingThreadInitializerwhich allows customization of the background logging thread, mainly for thread affinity or priority (#68)
v2.2.0
New features
- Added a
LogManager.Flushmethod, which can be useful in benchmarks - Added custom
TimeProvidersupport in the configuration (#62, requires .NET 8) - Added
%localDateand%localTimeplaceholders (#64)
Fixes
- Fixed
LogManager.RegisterAllEnumsFromto be safe to use with assemblies containing invalid types - Fixed enum support on .NET 6 under Linux
v2.1.1
- Fixed a race condition on shutdown where the last messages could be skipped
v2.1.0
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})
- An integer format can be used on string placeholders to specify a minimum field length, e.g.
- New prefix placeholders:
%newlineinserts a system-dependent newline%{column:N}inserts padding until the column indexNis reached%loggerCompactinserts 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(useTextWriterAppender(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 (
AppendingStrategysetting) - Added
LoggedMessage.Clone()to capture logged messages - Snapshot testing with Verify.ZeroLog
Configuration
- Added new convenience APIs for configuration:
ZeroLogConfiguration.SetLogLevel- New
LoggerConfigurationconstructor overloads - New initializer syntax for adding
Loggersto the collection:Loggers = { { NameA, LevelA }, { NameB, LevelB } }
- Made the
UseBackgroundThreadsetting obsolete: the worker thread is now always a background thread - Added a
LogManager.Configurationproperty
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
v2.0.0
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:is now equivalent to:_log.Info($"Hello {World()}!");
if (_log.IsInfoEnabled) { _log.Info() .Append("Hello ") .Append(World()) .Append("!") .Log(); }
- The
ILogEventinterface has been removed, it's replaced by theLogMessageclass, in order to remove slower interface calls. - The
ILoginterface has been removed, it's replaced by theLogclass, 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.