Write Microsoft.Extensions.Logging to kafka.
Install the Nuget package.
Install-Package Tuhu.Extensions.Logging.Structured.Kafka
In your testing project, add the following framework
ILoggingBuilder lb = ....;
lb.AddKafka("localhost:19200", "test")
.AddLayout("DateTime", new DateTimeOffsetLayout())
//.AddLayout("XXX", new YYYLayout())
.AddLayout("Exception", new ExceptionLayout());