All contributions

serilog/serilog

Serilog

A structured logging library for .NET. It records events from message templates, with named properties rather than plain text.

Language
C#
GitHub stars
8,064
Merged changes
1
Project site
serilog.net

What we changed

MessageTemplateParser no longer throws OverflowException when the alignment width in a template is int.MinValue. Such a template comes back as plain text, like other invalid alignments.

What this work shows

  • Message template parsing
  • Integer overflow edge cases
  • xUnit unit tests
What was broken

One log template ended in an exception

A template with the alignment -2147483648, such as "{Value,-2147483648}", passed int.TryParse, and Math.Abs(int.MinValue) threw OverflowException. Parse is meant to return text for invalid templates, but log.Information ended in an unhandled exception instead.

How we fixed it

Such an alignment is plain text

After reading the width we reject int.MinValue and return the raw text as a TextToken, as with "+10" or "10-1". The new AlignmentOfIntMinValueIsParsedAsText test failed before the fix and passes after it.

#2247

Merged change 1

  1. #2247 fix: avoid OverflowException when alignment width is int.MinValue Merged 13 September 2026

What it taught us

We look for edge values that break a documented contract: Math.Abs(int.MinValue) does not fit in an int, so a parser meant to return text for invalid templates threw instead. The fix follows the behaviour the library already had for other invalid input.

More about this technology: C# and .NET

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.