Skip to content

GroupByWrapper target

Rolf Kristensen edited this page Nov 27, 2021 · 3 revisions

Allow one to to take an entire batch of logevents and group-by ex. request-identifier. Splitting the batch into individual emails / reports.

Platforms Supported: All (Introduced with NLog 5.0)

Configuration Syntax

<targets>
  <target xsi:type="GroupByWrapper"
          name="String"
          key="Layout">
    <target xsi:type="wrappedTargetType" ...target properties... />
  </target>
</targets>

Parameters

  • Key - Layout used for grouping the LogEvents into smaller batches.

Example

Creates a buffer of the last 50 LogEvents, and flushes when receiving LogEvent with LogLevel.Error. Then groups the LogEvents by their individual request (Using ${activity} other correlationid). Then generates output only containing the LogEvents matching the failed request.

  <target name="String" xsi:type="AutoFlushWrapper" condition="level >= LogLevel.Error" flushOnConditionOnly="true">
    <target name="String" xsi:type="BufferingWrapper" bufferSize="50" overflowAction="Discard">
      <target name="String" xsi:type="GroupByWrapper" key="${ActivityId}">
        <target name="String" xsi:type="PostFilteringWrapper" defaultFilter="Ignore">
           <when exists="level >= LogLevel.Error" filter="Log"/>
           <target xsi:type="myTargetType" ...target properties... />
        </target>
      </target>
    </target>
  </target>
Clone this wiki locally