1

我已使用 Microsoft.Extensions.Logging SimpleConsole 将日志记录添加到两个项目(.net-5 和 .net-6),如下所示:

services.AddLogging(builder => builder
                                .AddSimpleConsole(options =>
                                {
                                    options.IncludeScopes = true;
                                    options.SingleLine = true;
                                    options.TimestampFormat = "yyyy-MM-dd hh:mm:ss ";
                                }));

但是当我使用以下方式记录自己的消息时:

_logger.LogInformation($"customer: {selectedCustomer.Name}");

“信息:”后面的部分包含我要记录的消息前面的日志类别。

2022-01-05 10:13:17 info: MySite.Pages.Customers[0] customer: admin

我记录的消息可能很长,我仍然希望在适合屏幕的一行中看到它们。因此,我怎样才能摆脱日志类别,让它只记录我的消息?

4

0 回答 0