我正在使用 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"
}
]
}
}
如果我使用像“@l = 'Information'”這樣的過濾器,Serilog會引起注意,但是任何基于 LogEvent 屬性的過濾嘗試都不起作用。
任何幫助,將不勝感激!
uj5u.com熱心網友回復:
Serilog.Expressions不需要貫穿Properties子物件:所有事件的屬性都是頂級名稱。
StatusCode 也是一個數字,而不是一個字串,因此您不需要在要排除的狀態代碼值陣列中使用引號。
你的表情應該是這樣的:
@l = 'Information' and StatusCode in [200, 302]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/379674.html
標籤:asp.net-mvc 串行
