1

I have a File Target as follow:

<target xsi:type="File" 
        name="f" 
        fileName="${basedir}/Logs/${event-properties:EmployeeID}.log" 
        ... 
/>

This file target logs the entries of each employee in a separate file based on the EmployeeID value, but some log entries don't have this EmployeeID property. How to log these entries to a default path ?

Is there syntax like this ?

fileName="${basedir}/Logs/${event-properties:EmployeeID || 'UnknownEmployee'}.log" 
KeyBored
  • 601
  • 4
  • 14

1 Answers1

3

The trick is to make use of the ambient layoutrenderer whenEmpty.

Example:

fileName="${basedir}/Logs/${event-properties:EmployeeID:whenEmpty=UnknownEmployee}.log"

See also: https://github.com/nlog/nlog/wiki/WhenEmpty-Layout-Renderer

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70