Reputation: 621
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"
Upvotes: 1
Views: 60
Reputation: 19847
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
Upvotes: 3