All contributions

NLog/NLog

NLog

A flexible structured logging library for many .NET platforms, configured through layouts, filters and targets.

Language
C#
GitHub stars
6,547
Merged changes
3
Project site
nlog-project.org

What we changed

A new cachedUntil option refreshes a cached layout value when the event time moves into a new hour or day, a new IncludePublicFields option writes an object's public fields to JSON, and the XML docs for filters state the default values of their properties.

What this work shows

  • NLog layout renderers and value caching
  • Time period boundaries with DateTime.Ticks
  • C# XML documentation comments
  • xUnit unit tests
What was broken

Filter defaults were missing from the docs

The issue asked for property defaults to be visible in the generated XML docs, meaning Sandcastle and IntelliSense hints, not only in the source. Earlier changes covered targets, layouts and wrappers, while the NLog.Filters namespace had not a single entry.

How we fixed it

Default and [Required] on every filter

Each of the 19 settable properties in NLog.Filters, from Filter.Action to the WhenRepeatedFilter options, has a remarks entry with its default, and those a filter cannot work without are marked [Required]. We left out the obsolete OptimizeBufferReuse on purpose, since it always returns true.

#6275

What was broken

Hourly refresh depended on when the app started

The cachedSeconds option counts from the moment the value was cached. A refresh, of an IP address for example, exactly at midnight or on the hour therefore only worked if the application started at exactly that time.

How we fixed it

cachedUntil=HourChange and DayChange

A new CachedUntil property clears the cached value when the event TimeStamp moves into a new hour or day, and also works in the short form ${local-ip:cachedUntil=HourChange}. It combines with cachedSeconds, the earlier deadline wins, and the period end is inclusive so it cannot overflow DateTime.MaxValue.

#6292

What was broken

The JSON serializer ignored public fields

The issue asked for the NLog JSON serializer to write fields, not only properties, since older applications keep their data in public fields. An object without public properties reached the log only as the result of ToString().

How we fixed it

The IncludePublicFields option

A new IncludePublicFields option in JsonSerializeOptions and in JsonLayout, off by default, writes the public fields of an object that has no public properties. In JsonLayout it is set the same way as MaxRecursionLimit. The fields live in the same cache entry as the properties, so serializers with and without the option share a type without affecting each other's output, and a field hidden in a derived class is written once.

#6274

Merged changes 3

  1. #6274 Add IncludePublicFields option to JsonSerializeOptions Merged 18 November 2026
  2. #6292 CachedLayoutRendererWrapper - Added CachedUntil to reset cached value when hour or day changes Merged 11 October 2026
  3. #6275 docs: document default values for Filters properties in XML docs Merged 5 September 2026

What it taught us

A new option in a public library is more than code: a property, factory registration, XML docs and tests at the hour and day boundary, all following the project's conventions. The expiry is computed from the event time, not from application start.

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.