Serilog Azure EventHub 接收器输出模板 json

Serilog Azure EventHub Sink output template json

所以,我正在努力解决这个问题。 我有 Serilog 并使用 EventHub 记录错误。 花了一段时间才找到,但我需要将它序列化为 JSON 所以我使用了这个:

logger = new LoggerConfiguration().WriteTo.Sink(new AzureEventHubSink(eventHubClient, new JsonFormatter()))
                .CreateLogger();

太棒了。现在,当我写异常时:

logger.Error(ex, "An Error Occurred");

它写了但异常写在 1 个字段中(大长强)。

有没有办法告诉 SeriLog 在其自己的字段中写入异常的每个 属性(将其视为带有字段的 SQL table)?

如何更改 outputTemplate 但仍然使用 JsonFormatter,因为没有重载来接受输出模板?

我正在使用流分析进行一些查询,它使每个异常 属性 作为其自己的字段列而不是整个 JSON 中只有 1 个字段变得更好(更好)字符串,我需要在另一个数据源上进行交叉连接。

谢谢。

看来唯一的办法就是继承自JsonFormatter,然后覆盖WriteException方法,写出有问题的属性....

    WriteJsonProperty("ClassName", exception.GetType(), ref delim, output);
    WriteJsonProperty("Message", exception.Message, ref delim, output);