serilog / serilog-expressions

An embeddable mini-language for filtering, enriching, and formatting Serilog events, ideal for use with JSON or XML configuration.
Apache License 2.0
193 stars 17 forks source link

Supply the list element index in the second #each parameter when enumerating #99

Closed nblumhardt closed 1 year ago

nblumhardt commented 1 year ago

This is useful when conditionally formatting the first or last element in a list, or when generating unique identifiers for each element - for example, when formatting HTML tables.

{#each e, i in ['a', 'b', 'c']}
  Element: {e}
  Index: {i}
{#end}

produces:

  Element: a
  Index: 0

  Element: b
  Index: 1

  Element: c
  Index: 2