I am trying to set up an ASP.NET Core 3.1 Web API to test the elk stack using Serilog v2.9 and Serilog.Sinks.Elasticsearch v8.0.1. This is all new to me and I'm just trying to figure things out. I seem to have everything working and can log simple things all day long and see them in both ES and Kibana. Trouble is I can't seem to destructure anything except anonymous types. To illustrate:
var data = new
{
SampleData = "Hello World!"
};
_logger.LogInformation("Destructured anonymous object: {@data}", data);
Produces the expected result. A nice shiny log entry with the object "data" serialized perfectly. Whereas:
var test = new TestClass
{
Guid = Guid.NewGuid(),
Timestamp = DateTime.UtcNow,
Title = "Testing this serialization!"
};
_logger.LogInformation("Destructred discrete type. {@test}", test);
Produces nothing at all. No exception, no entry in ElasticSearch. Nothing. TestClass is a simple class with only those 3 properties, all of which should serialize just fine. I can't figure this out. Here is my LoggerConfiguration:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUri))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true)
})
.CreateLogger();
What am I missing? Do I have to like, produce a property map or something to destructre non-anonymous objects? Is .Net Core 3.1 too new? I'm at a loss. Every example I've seen online says this should be working.