serilog-contrib / serilog-sinks-slack

A simple (yet customizable) Slack logging sink for Serilog
MIT License
41 stars 27 forks source link

Allow one channel per log level #46

Open phillijw opened 6 months ago

phillijw commented 6 months ago

It would be good if each log level (info, debug, trace, warning, error, critical, etc) could have their own channel specified to send messages to.

TrapperHell commented 6 months ago

I disagree that this is something that this library should handle, considering that there are libraries specialized for expression-based filtering. One such library is Serilog Expressions.

Assuming that you are loading the Serilog configuration from a JSON file, you could use something akin to this (switching from Console logging to Slack):

{
    "Serilog": {
        "Using": [ "Serilog.Expressions", "Serilog.Sinks.Console" ],
        "WriteTo": [
            {
                "Name": "Logger",
                "Args": {
                    "configureLogger": {
                        "Filter": [
                            {
                                "Name": "ByIncludingOnly",
                                "Args": {
                                    "expression": "(@l = 'Information')"
                                }
                            }
                        ],
                        "WriteTo": [
                            {
                                "Name": "Console"
                            }
                        ]
                    }
                }
            },
            {
                "Name": "Logger",
                "Args": {
                    "configureLogger": {
                        "Filter": [
                            {
                                "Name": "ByIncludingOnly",
                                "Args": {
                                    "expression": "(@l = 'Warning')"
                                }
                            }
                        ],
                        "WriteTo": [
                            {
                                "Name": "Console"
                            }
                        ]
                    }
                }
            }
        ]
    }
}