serilog-sinks-slackclient icon indicating copy to clipboard operation
serilog-sinks-slackclient copied to clipboard

Provide example renderer overload in appsettings configuration

Open Indrego opened this issue 6 years ago • 0 comments

In the readme it shows how to provide a custom renderer when configuring the sink in code:

var log = new LoggerConfiguration()
	.WriteTo.Slack("https://hooks.slack.com/services/T000/B000/XXXX",
                MyApp.MyRenderer.RenderMessage)
	.CreateLogger();

However, I'm struggling to do the same using the serilog configuration extension:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Slack.Core" ],
    "MinimumLevel": {
      "Default": "Debug"
    },
    "WriteTo": [
      {
        "Name": "Slack",
        "Args": {
          "webhookUri": "https://hooks.slack.com/services/T000/B000/XXXX",
          "restrictedToMinimumLevel": "Information",
          "renderMessageImplementation": "MyApp.MyRenderer::RenderMessage, MyApp"
        }
      }
    ]
  }
}
Unhandled Exception: System.InvalidCastException: Invalid cast from 'System.String' to 'Serilog.Sinks.Slack.Core.SlackSink+RenderMessageMethod'.
   at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   at Serilog.Settings.Configuration.StringArgumentValue.ConvertTo(Type toType, IReadOnlyDictionary`2 declaredLevelSwitches)
   at Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass20_0.<CallConfigurationMethods>b__3(<>f__AnonymousType7`2 <>h__TransparentIdentifier0)

What is the correct syntax of renderMessageImplementation in the appsettings.json to do this? I tried looking at the ConvertTo code but am not sure what I'm missing.

Indrego avatar Jun 26 '19 19:06 Indrego