Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mmaty 117 posts 311 karma points
    Jun 28, 2024 @ 09:57
    mmaty
    0

    Howto configure a log filter

    Hello everyone,

    we use a user-defined Serilog Sink that sends emails. We want to exclude some messages from the log to this sink. In earlier versions this was possible via the serilog.user.config file

    <add key="serilog:write-to:FFSmtp.filter" value="Failed to build models" />
    

    but since Umbraco 9 I don't see a way to configure that.

    The serilog docu suggests using a filter section:

    "Filter": [{
      "Name": "ByIncludingOnly",
      "Args": {
          "expression": "Application = 'Sample'"
      }
    }]
    

    This filters messages for all sinks. I could live with that, but I can't find any documentation on how to apply filter expressions to the log message. This stack overflow post suggests using @Message or @m but both don't work.

    "Filter": [{
      "Name": "ByIncludingOnly",
      "Args": {
          "expression": "@Message = 'Sample'"
      }
    }]
    

    Do you have an idea how to solve this?

    -mm

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Jun 28, 2024 @ 11:11
    Huw Reddick
    0

    do you have the Serilog.Expressions package installed?

  • mmaty 117 posts 311 karma points
    Jun 28, 2024 @ 11:42
    mmaty
    0

    Serilog.Expressins comes as dependency of Umbraco.Cms.Infrastructure.

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Jun 28, 2024 @ 12:03
    Huw Reddick
    0

    maybe the comparison is failing, perhaps try something like

    "Filter": [{
      "Name": "ByIncludingOnly",
      "Args": {
          "expression": "Contains(@m, 'Sample')"
      }
    }]
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies