1

I add FileSink as failureSink to ElasticsearchSink from appSettings.json. But "Cannot create instance of type 'Serilog.Core.ILogEventSink' because it is either abstract or an interface." I get an error. How do I fixed it?

"Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Elasticsearch"],
    "MinimumLevel": {
        "Default": "Error",
        "Override": {
            "Microsoft.Hosting.Lifetime": "Information",
            "Microsoft.AspNetCore": "Warning",
            "Microsoft": "Error",
            "System": "Error",
            "Quartz": "Error",
            "GraphQL": "Warning",
            "Hateoas": "Warning",
            "MassTransit": "Information"
        }
    },
    "WriteTo": [
        {
            "Name": "Elasticsearch",
            "Args": {
                "nodeUris": "http://17.172.25.115:9200",
                "indexFormat": "logstash",
                "templateName": "logstash-template",
                "emitEventFailure":  "WriteToFailureSink, WriteToSelfLog, RaiseCallback",
                "failureSink": {
                    "type": "Serilog.Sinks.File.FileSink, Serilog.Sinks.File",
                    "path": "failures.txt",
                    "fileSizeLimitBytes":  null 
                }
            }
        },
        {
            "Name": "Console",
            "Args": {
                "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
                "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
            }
        }
    ],
    "Enrich": [ "FromLogContext" ],
    "Properties": {
        "ApplicationName": "AselsanSatComPAMAStatic"
    }
},
rdmzcn
  • 151
  • 1
  • 3
  • 13

1 Answers1

0

there are some mandatory settings in FileSink that we need to configure before the instance of FileSink can be created. You can set something like following and it should work.

  "failureSink": {
    "type": "Serilog.Sinks.File.FileSink, Serilog.Sinks.File",
    "path": "failures.txt",
    "fileSizeLimitBytes": 1234567,
    "rollingInterval": "Day",
    "textFormatter": "Serilog.Formatting.Json.JsonFormatter"
  }
Tat Sean
  • 31
  • 1
  • 3
  • 1
    Please add code and data as text ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](//meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. – Adrian Mole Apr 17 '23 at 10:46