我正在尝试使用结构化日志记录并记录一个对象。
我在尝试记录对象时遇到了这个错误:System.IO.FileNotFoundException: 'Could not find file 'C:\Non-Existent-File'.'此异常在 FileInfo Length 属性中。
有没有办法让 NLog 忽略这个属性或只记录 Bar.ToString()?
public class Foo()
{
public FileInfo Bar {get;set} = FileInfo("C:\Non-Existent File");
// More properties
}
public class App
{
private static readonly Logger MyLogger = LogManager.GetLogger("MyLogger");
public App()
{
MyLogger.Info("Foo is [{@foo}]", Foo);
}
}
我尝试设置 json 布局 MaxRecursionLimit=0 但这似乎不起作用。
这些例子非常接近,如果需要可以用来变通,但不能完全回答我的问题: