最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Serilog Filter expression "ByExcluding" - Stack Overflow

programmeradmin2浏览0评论

I need the logs as follows

  1. Health Check should have single log entry for /health/live and /health/ready when Status 200. Currently 3 log entries for /health/live 3-10 log entries for /health/ready.
  2. Health Check should log all the warning and other Status code.

With no filters I could see the below logs

[11:19:19] [7b88516f-aa4b-4e9f-a8f0-9264e48ef899] [56e93ef5-dd95-4743-99d7-873b6132655d] [INF] Request starting HTTP/1.1 GET http://localhost:8800/health/live - null null (Microsoft.AspNetCore.Hosting.Diagnostics)
[11:19:20] [7b88516f-aa4b-4e9f-a8f0-9264e48ef899] [56e93ef5-dd95-4743-99d7-873b6132655d] [INF] Executing endpoint 'Health checks' (Microsoft.AspNetCore.Routing.EndpointMiddleware)
[11:19:20] [7b88516f-aa4b-4e9f-a8f0-9264e48ef899] [56e93ef5-dd95-4743-99d7-873b6132655d] [INF] Executed endpoint 'Health checks' (Microsoft.AspNetCore.Routing.EndpointMiddleware)
[11:19:20] [7b88516f-aa4b-4e9f-a8f0-9264e48ef899] [56e93ef5-dd95-4743-99d7-873b6132655d] [INF] HTTP GET /health/live responded 200 in 776.3736 ms (Serilog.AspNetCore.RequestLoggingMiddleware)
[11:19:20] [7b88516f-aa4b-4e9f-a8f0-9264e48ef899] [56e93ef5-dd95-4743-99d7-873b6132655d] [INF] Request finished HTTP/1.1 GET http://localhost:8800/health/live - 200 null application/json 779.5505ms (Microsoft.AspNetCore.Hosting.Diagnostics)

When I have the Filter as below and what is does is commented above on each filter

  "Filter": [
    {
      "Name": "ByExcluding",
      "Args": {
        // I could see no logs at all
        //"expression": "RequestPath like '/health/%' and not (@Message like '%Request finished%')"
        // on the below ones I see the last log of Request Finished is exlcuded and rest are logged
        //"expression": "RequestPath like '/health/%' and StatusCode = 200"
        //"expression": "RequestPath like '/health/%' and StatusCode = 200 and @Message not like '%Request finished%'"
      }
    }
  ],

When I have the Filter as below and what is does is commented above on each filter

  "Filter": [
    {
      "Name": "ByExcluding",
      "Args": {
        // I could see no logs at all
        //"expression": "RequestPath like '/health/%' and not (@Message like '%Request finished%')"
        // on the below ones I see the last log of Request Finished is exlcuded and rest are logged
        //"expression": "RequestPath like '/health/%' and StatusCode = 200"
        //"expression": "RequestPath like '/health/%' and StatusCode = 200 and @Message not like '%Request finished%'"
      }
    }
  ],
发布评论

评论列表(0)

  1. 暂无评论