Search code examples
c#asp.net-core.net-coremicrosoft-extensions-logging

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


is there a simple way to add ThreadId and ProcessId into the logs through Microsoft.Extensions.Logging without writing my own LoggingProvider?

Simply following code

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

should produce the following or similar output. (please assume I'm talking about 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

Solution

  • Nope, there's nothing built into for the console logger.