-
Notifications
You must be signed in to change notification settings - Fork 197
-
Notifications
You must be signed in to change notification settings - Fork 197
Get rid of Elasticsearch.Net dependency for Serilog.Formatting.Elasticsearch nuget package #224
Comments
I do agree that removing the Elasticsearch.Net reference does make the formatter more reusable. As far as I can quickly see, we only use it here directly: https://github.com/serilog/serilog-sinks-elasticsearch/blob/dev/src/Serilog.Formatting.Elasticsearch/ElasticsearchJsonFormatter.cs#L307 And that, in turn, calls the So it might be as easy as replacing the call with some other code instead of still having the dependency although via an adapter? |
I see that you raised a PR that indeed removed the reference. However, is this adapter needed, since the actual usage of the Elasticsearch functionality is minimal? And what to do when you only need the formatter itself, how do you provide the serialization functionality? |
So, I added adapter, because Elastichsearch sink accept IElasticsearchSerializer as a parameter and can be configured by library consumers. As I never use Elasticsearch sink and need only formatter, I don't know how often custom IElasticsearchSerializer is acctually used. Saving backward compatibility for Elastichsearch sink was a main reason to have adapter. |
The more lightweight we can make it, the better. So if the usage of ES in this formatter is only minimal and we can change that by some other code instead, I would say we go for that. |
So, it means that you suggest to remove |
I might misunderstand the issue or your question, sorry for that, but my impression is that the formatter should not need a reference to ES at all since the code that actually uses it is pretty minimal. So remove the usage altogether and replace it with a direct call to a JSON text writer instead. Then there should be no need to have custom implementations. The actual sink itself uses the formatter regardless of the actual new implementation of the serializer in the formatter. |
@mivano, just to clarify, which JSON text writer you mean? |
Ah I see now. Yes, you are right; there is that serializer call to write the object to json which it gets indeed from Elasticsearch. It makes sense to make that abstract so you can pass in Newtonsoft or Elasticsearch, or in the future the one that is referenced in issue elastic/elasticsearch-net#3656. Sorry for the confusion on my part, I think your original PR was a correct one. |
No problem, I recreated initial PR. Can you review it, again? Also, I found out interesting thing: file under |
Looks good! Yes that file is strange. The correct name should be with Elasticsearch. So lowercase second s. |
At the moment, there is
Elasticsearch.Net
dependency inSerilog.Formatting.Elasticsearch
nuget package. FromElasticsearch.Net
is used onlyIElasticsearchSerializer
interface. It's not a big issue due toSerilog.Sinks.Elasticsearch
uses it for communication with ES, however, in case of using inly formatter without sink, it would be good to have dependencies as less as possible.To remove
Elasticsearch.Net
dependency fromSerilog.Formatting.Elasticsearch
it can be specified customSerializer
interface inSerilog.Formatting.Elasticsearch
project and write a simple adapter inSerilog.Sinks.Elasticsearch
betweenIElasticsearchSerializer
and customSerializer
interface. In such case,public contracts of ES Sink will not be changed.What do you think about it?
The text was updated successfully, but these errors were encountered: