我有一个具有
byte[]
属性的实体,当 DBUpdateException
发生时,它会将其倒入 json 日志中,因为 DbUpdateException
包含 Entries
列表,其中包括每个条目的 ntity 属性。我想知道是否有一种方法可以防止记录这一属性。我正在使用NLog 5.2.5
(JsonLayout),EF Core 5
。
您可以像这样覆盖对象类型的属性选择:
LogManager.Setup().SetupSerialization(s =>
s.RegisterObjectTransformation<DBUpdateException>(ex => new {
Type = ex.GetType().ToString(),
Message = ex.Message,
StackTrace = ex.StackTrace,
Source = ex.Source,
Data = ex.Data,
InnerException = ex.InnerException,
})
);
另请参阅:https://github.com/NLog/NLog/wiki/How-to-use-structed-logging#customize-object-reflection