c# - Serilog 在输出中显示属性名称

标签 c# serilog

如果我有这个:

logger.Information("this is a message with {property_name}", "value");

我怎么输出这个:

this is a message with property_name = value

代替:

this is a message with value

最佳答案

通过 Serilog 写入的日志消息的显示输出由 formatter 完成由您正在写入的接收器使用。每个接收器都可以使用不同的格式化程序,并且可以不同地表示输出。

您要求的不是默认格式化程序可以做的事情,因此您必须自己编写 custom text formatter ,然后告诉接收器使用您的格式化程序而不是默认的格式化程序。

Formatting Output

Serilog provides several output formatting mechanisms.

  • Formatting plain text
  • Formatting JSON
  • Custom text formatters

关于c# - Serilog 在输出中显示属性名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59126708/

相关文章:

c# - 除了强制转换 IntPtr 来增加它之外,还有其他方法吗?

C# 加入列表。 LINQ。无法创建常量类型

c# - 在 C# Unity3D 中将一个场景加载到另一个场景时播放动画?

.net-core - 如何在 AWS Cloudwatch 上的 Serilog 的结构化日志输出中显示带有替换参数的日志消息

c# - 如何只针对特定环境写入日志?

c# - C#-无法使用sqlite数据库删除datagridview中的多行

C# 静态属性锁定

c# - .NET 6 Web API 中的 AddSerilog 和 UseSerilog 有什么区别?

serilog - 是否可以将 Serilog 配置为截断(即清空)每个新进程的日志文件?

serilog - 如何在 Serilog 中将对象序列化为字符串?