简体   繁体   English

LogContext 属性的集合

[英]Collection of LogContext Properties

How can I get collection of properties current LogContext in ASP.NET Core custom Middleware?如何在 ASP.NET 核心自定义中间件中获取当前 LogContext 的属性集合? I push property in Middleware like this:我像这样在中间件中推送属性:

var profile = context.Request.Host.Host;

using (LogContext.PushProperty("TestProp", "MyCustomProp"))
using (LogContext.PushProperty("Profile", profile))
{
  await _next(context);
}

Then I want to get the whole collection of properties, how can I do that?然后我想获得整个属性集合,我该怎么做?

The interface is deliberately designed not to surface such information - the information is purely for the use of Enrich.FromLogContext and subject to change.该界面特意设计为不显示此类信息 - 这些信息仅供Enrich.FromLogContext使用,可能会发生变化。 You can read the impl .您可以阅读impl

You'll thus need to manage this externally.因此,您需要在外部进行管理。


One thing that is supported common practice is to use {Properties} in your message template to render all the properties you added via:支持的一件事是在您的消息模板中使用{Properties}来呈现您通过以下方式添加的所有属性:

.Enrich.FromLogContext() 
.WriteTo.Console("[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties} {NewLine}{Exception})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM