有没有一种方法可以通过配置中的属性来丰富日志? [英] Is there a way to enrich the log with a property from configuration?
本文介绍了有没有一种方法可以通过配置中的属性来丰富日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以这样添加浓缩器:
I know I can add enrichers this way:
{
"Serilog": {
"Using": [
"Serilog",
"Serilog.Enrichers.Environment",
"Serilog.Enrichers.Process",
...
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithProcessId"
]
...
我可以对属性( ApplicationName
)进行同样的操作吗?
Can I do the same for a property (ApplicationName
)?
推荐答案
一种方法是使用属性。但是,浓缩属性的配置有一个警告,那就是它是顶级配置,而不是浓缩配置:
One way of doing this is with properties. But the configuration for enrichment properties has a caveat that it's a top level configuration and not an enrichment configuration:
{
"Serilog": {
"Using": [
"Serilog",
"Serilog.Enrichers.Environment",
"Serilog.Enrichers.Process",
...
],
"Properties": {
"ApplicationName": "my application"
},
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithProcessId"
]
...
这将导致配置读取器调用以下内容:
This will cause the configuration reader to call something like this:
loggerConfiguration.Enrich.WithProperty("ApplicationName", "my application");
这篇关于有没有一种方法可以通过配置中的属性来丰富日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文