Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide example renderer overload in appsettings configuration #17

Open
Indrego opened this issue Jun 26, 2019 · 0 comments
Open

Provide example renderer overload in appsettings configuration #17

Indrego opened this issue Jun 26, 2019 · 0 comments

Comments

@Indrego
Copy link

Indrego commented Jun 26, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant