So I am using NLog and the JSON Layout Target to log my .Net Application and its data which is so far working mostly fine.
However I have an issue where some of my objects contain Byte Arrays of large FileData that get included in the log file output which for file size reasons I don't want to include.
Looking at the NLOG tutorials available there is an "excludeProperties" attribute that I can include in the Layout Configuration however I can't seem to get this to actually work specifically.
So If my Object looks like,
public class Station : IStation
{
public int ID { get; set; }
public string Name { get; set; }
public string MACAddress { get; set; }
public string ComputerName { get; set; }
}
and I use the following Layout Config in NLog,
<layout type='JsonLayout'>
<attribute name='Time' layout='${longdate}' />
<attribute name='Level' layout='${level:upperCase=true}'/>
<attribute name='Call Site' layout='${callsite}'/>
<attribute name='Data' encode='false' >
<layout type='JsonLayout'
includeAllProperties="true"
maxRecursionLimit="20"
excludeProperties="Name"
>
<attribute name='message' layout='${message}' encode='false' />
<attribute name='exception' layout='${exception}' />
</layout>
</attribute>
</layout>
Then use the structured logging call of:
_logger.Debug("Station Details:{@0}", Station);
The NLog output still includes the Name attribute in the produced log. In this example its just the name property however other objects include large file data being brought down from a DB and I would like to exclude those specific properties...
So how do I specifically target the Name Property of the Station Object remembering that the "Name" Property will exists in other objects.
I've tried the following Attributes and they all still include the Name property in the output.
excludeProperties="_Name"
excludeProperties="Name"
excludeProperties="Station_Name"
excludeProperties="IStation_Name"
What is the correct "Syntax" for ignoring properties when using structured logging in NLog?
question from:
https://stackoverflow.com/questions/65839859/nlog-structured-logging-ignore-property-by-name 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…