排除http 200和http 302的Serilog表达式?
Serilog expression to exclude http 200 and http 302?
我正在使用 serilog,它可以很好地将 http 请求记录到我的 asp.net 核心 Web 应用程序。
不过我想过滤掉http 200和http 302的噪音(基本上只对5xx和4xx感兴趣)。
我在以下方面尝试了很多变体:
... snip ...
"Using": [ "Serilog.Expressions" ],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "@l = 'Information' and Properties.StatusCode in ['200', '302']"
}
}
],
... snip ...
但没有成功。
LogEvent 属性类似于 (:
{
"TimeStamp": "2021-12-09T09:00:18.1586954",
"Level": "Information",
"Message": "HTTP \"GET\" \"/xxx/yyy\" responded 200 in 50.2048 ms",
"MessageTemplate": "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms",
"Properties": {
"RequestMethod": "GET",
"RequestPath": "/xxx/yyy",
"StatusCode": 200,
"Elapsed": 50.2048,
"SourceContext": "Serilog.AspNetCore.RequestLoggingMiddleware",
"RequestId": "8000050f-0006-eb00-b63f-84710c7967bb"
},
"Renderings": {
"Elapsed": [
{
"Format": "0.0000",
"Rendering": "50.2048"
}
]
}
}
Serilog 是 注意我是否使用像“@l = 'Information'”这样的过滤器,但是任何基于 LogEvent 属性的过滤尝试都不起作用。
如有任何帮助,我们将不胜感激!
Serilog.Expressions 不需要点缀 Properties
子对象:事件的所有属性都是顶级名称。
StatusCode
也是一个数字,而不是字符串,因此您不需要在要排除的状态代码值数组中使用引号。
你的表情应该是这样的:
@l = 'Information' and StatusCode in [200, 302]
我正在使用 serilog,它可以很好地将 http 请求记录到我的 asp.net 核心 Web 应用程序。
不过我想过滤掉http 200和http 302的噪音(基本上只对5xx和4xx感兴趣)。
我在以下方面尝试了很多变体:
... snip ...
"Using": [ "Serilog.Expressions" ],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "@l = 'Information' and Properties.StatusCode in ['200', '302']"
}
}
],
... snip ...
但没有成功。
LogEvent 属性类似于 (:
{
"TimeStamp": "2021-12-09T09:00:18.1586954",
"Level": "Information",
"Message": "HTTP \"GET\" \"/xxx/yyy\" responded 200 in 50.2048 ms",
"MessageTemplate": "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms",
"Properties": {
"RequestMethod": "GET",
"RequestPath": "/xxx/yyy",
"StatusCode": 200,
"Elapsed": 50.2048,
"SourceContext": "Serilog.AspNetCore.RequestLoggingMiddleware",
"RequestId": "8000050f-0006-eb00-b63f-84710c7967bb"
},
"Renderings": {
"Elapsed": [
{
"Format": "0.0000",
"Rendering": "50.2048"
}
]
}
}
Serilog 是 注意我是否使用像“@l = 'Information'”这样的过滤器,但是任何基于 LogEvent 属性的过滤尝试都不起作用。
如有任何帮助,我们将不胜感激!
Serilog.Expressions 不需要点缀 Properties
子对象:事件的所有属性都是顶级名称。
StatusCode
也是一个数字,而不是字符串,因此您不需要在要排除的状态代码值数组中使用引号。
你的表情应该是这样的:
@l = 'Information' and StatusCode in [200, 302]