Serilog.Exception 解构器的 JSON 配置 [英] JSON Configuration for Serilog.Exception destructurers

查看:41
本文介绍了Serilog.Exception 解构器的 JSON 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Serilog 添加到项目中,并且我特别想添加 Serilog.Exceptions.遵循 指南 我已经成功添加了异常丰富器,但我还需要提到的解构在链接页面中.

I am adding Serilog to the project and I specifically want to add Serilog.Exceptions as well. Following the guideline I've added just the Exceptions enricher successfully, but I also need the destructures mentioned in the linked page.

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

The following works fine using fluent configuration:

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

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

However, I'm struggling to get it configured using JSON config like this:

config.ReadFrom.Configuration(context.Configuration);

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

Here's what I've tried already without much luck:

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

还有:

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

如何使用 JSON 配置 fluent 版本?

How do I configure the fluent version using JSON?

推荐答案

目前不支持从 Configuration 中配置 Destructure,这是设计的.

Currently, it is not supported to configure Destructure from Configuration which is by design.

建议通过代码进行配置.

It is recommended to configure through code.

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

这篇关于Serilog.Exception 解构器的 JSON 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆