健康檢查和度量接口的大量請求會產生許多不必要的請求日誌,因此在配置serilog的時候可以對請求路徑爲/heathz和/metrics不進行日誌記錄。配置如下
new LoggerConfiguration() .Filter.ByExcluding(
e => e.Properties.TryGetValue("RequestPath", out var value) &&
(value.ToString() == "\"/metrics\"" || value.ToString() == "\"/healthz\""))
如果健康檢查的路徑不確定是/healthz 可改爲 value.ToString().StartWith("\"/health").要過濾其他路徑請求的日誌也可照此設置