I am trying to use structured logging and log an object.
I run into this error when trying to log the object: System.IO.FileNotFoundException: 'Could not find file 'C:\Non-Existent-File'.' This exception is in the FileInfo Length property.
Is there a way to have NLog ignore this one property or just log 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);
}
}
I tried setting the json layout MaxRecursionLimit=0 and that didn't seem to work.
These examples are very close and could be used to work around if needed, but don't quite answer my question: