使用Serilog解构Object时指定分隔符

问题描述 投票:0回答:1

在 Serilog 中使用

@
字符解构复杂对象时,默认使用“:”(冒号)作为分隔字符。我希望它是“=”(等号)。这可能吗?

using Serilog;
using Serilog.Events;
    
public class myClass
{
   public void myMethod()
   {
      var logger = new LoggerConfiguration().WriteTo().EventLog("myapp");
      var myComplexObject = new 
      {
         property1 = "prop1",
         property2 = "prop2"
      };
      logger.Information("{@complex}", myComplexObject);
   }
}

输出:

{ complex:{ property1:"prop1", property2:"prop2" }}

所需输出:

{ complex:{ property1="prop1", property2="prop2" }}

这可能吗?

c# .net serilog
1个回答
0
投票

您可以实施您的自定义格式。可以通过继承

ITextFormatter
接口来创建。

自定义格式化程序的文档

© www.soinside.com 2019 - 2024. All rights reserved.