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

标签 c# asp.net-core .net-core microsoft-extensions-logging

有没有一种简单的方法可以通过 Microsoft.Extensions.LoggingThreadIdProcessId 添加到日志中,而无需编写我自己的 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

最佳答案

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

关于c# - 如何将 ThreadId 和 ProcessId 添加到每个条目的日志输出中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40537721/

相关文章:

c# - 在上传期间调整和优化网页图像的最佳类别是什么?

docker - Azure DevOps 版本 "rzc generate exited with code 1"

visual-studio-2013 - 如何将 ASP.NET 5 模板添加到 Visual Studio 2013 Update 5?

asp.net-core - .NET Core SDK 安装程序无法在 Windows 2012 R2 Standard 上安装

c# - 在 C# 程序中使用 C++11

c# - System.Data.SqlClient.SqlException : 'Incorrect syntax near ' ='.' on Datatable and object

c# - 在 C# 中使用丢弃作为返回方法

asp.net-core - 挑战在 Asp .Net Core 3 中究竟意味着什么?

.net-core - 在 azure functions 3 中,我可以将日志过滤到应用程序见解和不同级别的控制台吗

c# - Action <T> 用作参数