serilog-contrib / serilog-sinks-slackclient

Slack Sink for Serilog
Apache License 2.0
27 stars 15 forks source link

Programatically change Args CustomChannel so it can be dinamic #28

Open alexvazquez opened 1 year ago

alexvazquez commented 1 year ago

I have Serilog slack configuration in appsettings.json:

{ "Name": "Slack", "Args": { "WebHookUrl": "https://hooks.slack.com/services/xxxx/xxxxx/xxxxxxx", "CustomChannel": "#dev-log", "CustomUserName ": "Slack Logger", "BatchSizeLimit": 20, "QueueLimit": 1000, "CustomIcon": ":ghost:", "TimestampFormat": "o", //"MinimumLogEventLevel": "Warning" "restrictedToMinimumLevel": "Warning" } }

I need to change in runtime the CustomChannel because in my code depending of logic I should notify to different channels.


` 
LogContext.PushProperty("Environment", environment.ToString());
                        LogContext.PushProperty("UserName", loggedUserName);
                        LogContext.PushProperty("ErrorUID", logException.ErrorUid.ToString());
                        LogContext.PushProperty("SecuritySessionID", sessionUid);

                        // *** HERE I NEED TO SET THE CustomChannel PROPERTY *** //

                        _logger.LogError(exception, $"An error with ID {errorUid} ocurred.");`

Any clue?