1

我正在将 Serilog 添加到项目中,我也特别想添加Serilog.Exceptions。按照指南,我成功地添加了异常丰富器,但我还需要链接页面中提到的解构。

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

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 配置流畅的版本?

4

1 回答 1

1

目前,不支持Destructure从设计的配置中进行配置。

建议通过代码配置。

参考:添加对 serilog-settings-configuration #58 的支持

于 2019-10-30T09:57:38.133 回答