【问题标题】:Is there a way to enrich the log with a property from configuration?有没有办法使用配置中的属性来丰富日志?
【发布时间】:2018-06-01 03:00:18
【问题描述】:

我知道我可以通过这种方式添加浓缩器:

{
  "Serilog": {
    "Using": [
      "Serilog",
      "Serilog.Enrichers.Environment",
      "Serilog.Enrichers.Process",
      ...
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithProcessId"
    ]
...

我可以对属性 (ApplicationName) 执行相同的操作吗?

【问题讨论】:

  • 你为什么不写你自己的浓缩器?
  • 这很有帮助,@mason!

标签: configuration serilog


【解决方案1】:

一种方法是使用属性。但是扩充属性的配置有一个警告,它是顶级配置而不是扩充配置:

{
  "Serilog": {
    "Using": [
      "Serilog",
      "Serilog.Enrichers.Environment",
      "Serilog.Enrichers.Process",
      ...
    ],
    "Properties": {
      "ApplicationName": "my application"
    },
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithProcessId"
    ]
...

这将导致配置读取器调用如下内容:

loggerConfiguration.Enrich.WithProperty("ApplicationName", "my application");

【讨论】:

    猜你喜欢
    • 2012-01-09
    • 1970-01-01
    • 2015-11-21
    • 2021-09-30
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多