-
Notifications
You must be signed in to change notification settings - Fork 831
Description
Description
With the latest version of Serilog it appears that the behaviour of what properties are logged has changed from an earlier version (2.12)
Here's the old output:
2024-08-20 09:12:09 [Information] Testing of destructing! OuterObjectToLog { Name: "Test", Description: "My Description" }
Here's the new output with the same object structure.
[09:09:52 INF] Testing of destructing! {"Name": "Test", "Description": "My Description", "InnerObject": {"InnerObjectName": "InnerObject", "InnerObjectDescription": "My Inner Object Description", "$type": "InnerObjectNotToLog"}, "$type": "OuterObjectToLog"}
Reproduction
using Serilog;
namespace SerilogTest
{
internal class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
OuterObjectToLog outerObjectToLog = new OuterObjectToLog("Test", "My Description",
new InnerObjectNotToLog("InnerObject", "My Inner Object Description"));
Log.Information("Testing of destructing! {@OuterObject}", outerObjectToLog);
// Finally, once just before the application exits...
Log.CloseAndFlush();
}
}
public class OuterObjectToLog (string name, string description, InnerObjectNotToLog innerObject)
{
public string Name { get; set; } = name;
public string Description { get; set; } = description;
**public InnerObjectNotToLog InnerObject { private get; set; } = innerObject;** // note the private getter and likely unexpected
}
public class InnerObjectNotToLog(string name, string description)
{
public string InnerObjectName { get; set; } = name;
public string InnerObjectDescription { get; set; } = description;
}
}
Expected behavior
Expecting that the property InnerObject is not included in the serilog output.
Relevant package, tooling and runtime versions
Version 4.0.1, .NET 8 on Windows 11.
Likely related to changes made in this commit? 580c55f