Closed lhyqy5 closed 5 years ago
this config does not affect Elasticsearch's default serializer Elasticsearch.Net.LowLevelRequestResponseSerializer
which use Elasticsearch.Net.SimpleJson
Looks like SimpleJson is being replaced https://github.com/elastic/elasticsearch-net/pull/3608
If you are very good, then you can setup dependency-injection with NLog, so when NLog loads the nlog.config, then you can override the creation of the ElasticSearchTarget-object (and assign your custom implementation of IElasticsearchSerializer):
var defaultConstructor = NLog.Config.ConfigurationItemFactory.Default.CreateInstance;
NLog.Config.ConfigurationItemFactory.Default.CreateInstance.CreateInstance = type =>
{
if (type == typeof(ElasticSearchTarget))
return new ElasticSearchTarget() { ElasticsearchSerializer = myFunkySerializer };
return defaultConstructor(type);
};
https://github.com/NLog/NLog/wiki/Dependency-injection-with-NLog
Just make sure to setup the factory-logic before loading the NLog-config. Or perform a reload of the NLog-config after having setup the factory-logic.
I have tried your solution, it works well, Thanks.
When logging a self-referencing loop object, the program just aborted with a message 'Process is terminating due to StackOverflowException'.
It's seems caused by serializing in
ElasticSearch.Net.PostData
I found there is an
ElasticsearchSerializer
property in target config, I wonder know how can I config this property to use my custom Serializer in thenlog
config file.