JSON Serilog.Exception 解构器的配置

JSON Configuration for Serilog.Exception destructurers

我正在将 Serilog 添加到项目中,我特别想添加 Serilog.Exceptions。在 guideline 之后,我成功地添加了 Exceptions enricher,但我还需要链接页面中提到的解构。

以下使用流畅的配置工作正常:

config.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new ExceptionDestructurer[]
    {
        new DbUpdateExceptionDestructurer(),
        new SqlExceptionDestructurer()
    }));

但是,我正在努力使用 JSON 这样的配置来配置它:

config.ReadFrom.Configuration(context.Configuration);

这是我已经尝试过但运气不佳的方法:

"Enrich": [
      { "Name": "FromLogContext" },
      {
        "Name": "WithExceptionDetails",
        "Args": {
          "With": "DbUpdateException, SqlException"
        }
      } 
]

还有:

"Enrich": [ "FromLogContext", "WithExceptionDetails" ],
"Destructure": [
      {
        "Name": "With",
        "Args": { "policy": "DbUpdateException, SqlException" }
      }
]

如何使用JSON配置fluent版本?

目前不支持从设计的配置中配置 Destructure

建议通过代码配置

参考:Add support for serilog-settings-configuration #58