1

I created the custom sentry sink inside my API project.

public class SentrySink : ILogEventSink {...}

I also created an extension method for my sink so that I can connect my sink through logging configuration.

 public static LoggerConfiguration Sentry(this LoggerSinkConfiguration loggerConfiguration, 
        string dsn, 
        string release = null, 
        string environment = null,
        LogEventLevel restrictedToMinimumLevel = LogEventLevel.Information, 
        IFormatProvider formatProvider = null)
    {...}

When I use

 Log.Logger = new LoggerConfiguration()
               .ReadFrom.Configuration(configuration)
               .WriteTo.Sentry(configuration["Sentry:Dsn"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)

Everything works fine and log's are in sentry.

But when I set up the configuration in appsetting.json as

 "WriteTo": [
  { "Name": "Sentry" }, ...

without defining config in LoggerConfiguration the log's are not sent to sentry.

Do I need to implement something more so that I can use configs from appsetting.json? Thanks.

1 Answers1

0

You'll need to include at least "Args": {"dsn": ...}, because the dsn parameter is not optional.

You may also need a "Using": ["YourAssemblyContainingSink"] statement to ensure the configuration method is found, depending on the deployment target, and to check that the sink assembly is copied to your project's output directory.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101