【发布时间】:2021-01-22 05:41:15
【问题描述】:
所以我正在使用 NLog 和 JSON 布局目标来记录我的 .Net 应用程序及其数据,到目前为止工作正常。
但是我有一个问题,我的一些对象包含大文件数据的字节数组,这些字节数组包含在日志文件输出中,出于文件大小的原因我不想包含。
查看可用的 NLOG 教程,有一个“excludeProperties”属性,我可以将其包含在布局配置中,但我似乎无法让它真正发挥作用。
所以如果我的对象看起来像,
public class Station : IStation
{
public int ID { get; set; }
public string Name { get; set; }
public string MACAddress { get; set; }
public string ComputerName { get; set; }
}
我在 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>
然后使用结构化日志调用:
_logger.Debug("Station Details:{@0}", Station);
NLog 输出仍然在生成的日志中包含 Name 属性。在此示例中,它只是 name 属性,但是其他对象包括从数据库中删除的大文件数据,我想排除这些特定属性...
那么我如何专门针对 Station 对象的 Name 属性,记住“Name”属性将存在于其他对象中。
我已经尝试了以下属性,它们仍然在输出中包含 Name 属性。
excludeProperties="_Name"
excludeProperties="Name"
excludeProperties="Station_Name"
excludeProperties="IStation_Name"
在 NLog 中使用结构化日志时忽略属性的正确“语法”是什么?
【问题讨论】: