如何将 ThreadId 和 ProcessId 添加到每个条目的日志输出中

How to add ThreadId and ProcessId into the log output for each entry

有没有简单的方法通过Microsoft.Extensions.Logging[将ThreadIdProcessId添加到日志中 不写我自己的 LoggingProvider?

只需遵循代码

Logger.LogInformation("This is a test of the emergency broadcast system.");

应该产生以下或类似的输出。 (请假设我说的是 ConsoleLogger)

info: [{ProcessId}:{ThreadId}] This is a test of the emergency broadcast system.
  • For those who are familiar with serilog, I'm looking for the features called output template and defining global property
  • Please do not suggest any third party library

不,控制台记录器没有内置任何内容。