I have installed Elasticsearch locally on my Windows 7 machine. It is working properly and I can query it using postman. Using Postman, I have also created an index called cmstest. This has a table called zdsf. If I get the mapping (http://localhost:9200/cmstest/_mapping) for this index I get the following:
I can post entries to this table as well using Postman.
Now, I am trying to use Serilog from my .NET 4.5 application to log to this localhost instance of Elasticsearch.But nothing seems to be working. Here is my code:
var elasticUri = new Uri("http://localhost:9200/cmstest/zdsf");
var loggerConfig = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(elasticUri)
{
AutoRegisterTemplate = true
});
zdsf z = new zdsf();
z.filedate = DateTime.Now;
z.filename = "File2";
var logger = loggerConfig.CreateLogger();
var jsonString = new JavaScriptSerializer().Serialize(z);
logger.Error(jsonString);
I have tried using the following URLs:
http://localhost:9200/cmstest/zdsf
I have tried setting AutoRegisterTemplate to true as well as false. But Serilog doesn't seem to be writing anything to elasticsearch. It doesn't even give an exception. It just finishes without logging anything.
Another interesting thing is that fiddler doesn't show any traffic to http://localhost:9200 when serilog is supposed to be doing the logging. But it shows traffic when I make requests through Postman.
What am I doing wrong? How can I get Serilog to work?
UPDATE 1: Updated ElasticSearch.Net nuget package
I discovered that the Sink was using an old version of ElasticSearch.Net. So, I deleted the ElasticSearch.Net nuget package and downloaded the latest. This also added the needed BindingRedirects in my app.config. But logging to ElasticSearch still doesn't work.