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

Error handling when used in an API

Open lokimon opened this issue 5 years ago • 2 comments

A few questions before you begin:

Is this an issue related to the Serilog core project or one of the sinks or community projects.
This issue list is intended for Serilog Elasticsearch Sink issues. If this issue relates to another sink or to the code project, please log on the related repository. Please use Gitter chat and Stack Overflow for discussions and questons.

Does this issue relate to a new feature or an existing bug?

  • [x] Bug
  • [ ] New Feature

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package. Serilog.Sinks.Elasticsearch 8.0.1

What is the target framework and operating system? See target frameworks & net standard matrix.

  • [x] netCore 2.0
  • [ ] netCore 1.0
  • [ ] 4.7
  • [ ] 4.6.x
  • [ ] 4.5.x

Please describe the current behavior? Is there a way to get errors out of the serilog.sinks.elasticsearch module when used in an API?

Inside my appsettings.json I have the following configured.

"Name": "Elasticsearch", "Args": { "nodeUris": "http://api.myco.com:9200/apidev/_doc", "indexFormat": "custom-index-{0:yyyy.MM}", "connectionGlobalHeaders": "Authorization=Basic TWxhc3RpYzpmUDcyVXJ0bjhUZ3lLbmcz", "connectionTimeout": 5, "emitEventFailure": "ThrowException", "bufferBaseFilename": "logs/serilog-web-buffer", "bufferFileSizeLimitBytes": 5242880, "bufferLogShippingInterval": 5000, "bufferRetainedInvalidPayloadsLimitBytes": 5000, "bufferFileCountLimit": 31, "deadLetterIndexName": "deadletter-{0:yyyy.MM}" }

When I'm not connected to the network or elasticsearch is rejecting my log messages due to incompatible index, I expect to get an error somewhere.

I have tried all the options WriteToSelfLog WriteToFailureSink ThrowException RaiseCallback

I have yet to receive any error message indicating anything is wrong.

Also, the WriteToFailureSink option does not make sense to me as it is defined like this. "failureSink": "My.Namespace.MyFailureSink, My.Assembly.Name" But I haven't found any documentation on what that is expecting, or how to write it to a file.

Any help would be greatly appreciated.

Please describe the expected behavior? Failures to log to ElasticSearch in an API would send a notification somewhere that something is wrong.

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem

lokimon avatar Nov 26 '19 19:11 lokimon

I am also looking to get the actual error somewhere. When creating the ElasticSearchSinkOptions, the exception should be supplied when FailureCallback is invoked. Right now it's only invoking it with what failed, not why, which is much more important.

zeroregard avatar Jan 16 '20 15:01 zeroregard

You can combine the options, so it logs to selflog and send the event to the failure sink. I normally do not use the appSettings integration, so try with setting the failure sink explicitly to see if that works?

mivano avatar Jan 21 '20 15:01 mivano