Skip to content

Commit 95d09ce

Browse files
author
Alex McCool
committed
update elasticsearch.net to include default memory streams to prevent extensive memory usage due to pooling.
Allow for insecure HTTPS connections, bypassing cert validation
1 parent bf103c4 commit 95d09ce

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

example/SampleApp/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public Program()
3939
.AddEventSourceLogger()
4040
.AddElasticSearch(options =>
4141
{
42-
options.ElasticsearchEndpoint = new Uri(@"http://localhost:9200/");
42+
//options.ElasticsearchEndpoint = new Uri(@"http://localhost:9200/");
43+
//options.ElasticsearchEndpoint = new Uri(@"https://elasticsearch.mgmc.rauland/");
44+
options.ElasticsearchEndpoint = new Uri(@"http://es.devint.dev-r5ead.net:9200/");
4345
//options.IndexName = "trace";
4446
});
4547
});

src/ElasticSearch.Extensions.Logging/AM.Extensions.Logging.ElasticSearch.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
<Authors>amccool</Authors>
77
<Product>AM.Extensions.Logging.ElasticSearch</Product>
88
<Description>Microsoft.Extensions.Logging posting to ElasticSearch</Description>
9-
<Copyright>2029</Copyright>
9+
<Copyright>2021</Copyright>
1010
<PackageTags>ElasticSearch;ILogger;Monitoring;kibana;Microsoft.Extensions.Logging;logging;MEL</PackageTags>
1111
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
1212
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1313
<IncludeSymbols>true</IncludeSymbols>
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Elasticsearch.Net" Version="[6.8.2,7.0)" />
17+
<PackageReference Include="Elasticsearch.Net" Version="6.8.9" />
1818
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
1919
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.1.1" />
2020
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
2121
<PrivateAssets>all</PrivateAssets>
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2323
</PackageReference>
2424
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
25-
<PackageReference Include="System.Reactive.Linq" Version="3.1.0" />
25+
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
2626
</ItemGroup>
2727

2828
</Project>

src/ElasticSearch.Extensions.Logging/ElasticSearchLoggerProvider.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Reactive.Concurrency;
77
using System.Reactive.Linq;
8+
using System.Threading;
89
using System.Threading.Tasks;
910
using Elasticsearch.Net;
1011
using Microsoft.Extensions.Logging;
@@ -77,6 +78,7 @@ private ElasticLowLevelClient CreateNewElasticLowLevelClient(Uri elasticSearchEn
7778
var singleNode = new SingleNodeConnectionPool(_optionsMonitor.CurrentValue.ElasticsearchEndpoint);
7879

7980
var cc = new ConnectionConfiguration(singleNode, new ElasticsearchJsonNetSerializer())
81+
//.ServerCertificateValidationCallback((obj, cert, chain, policyerrors) => true)
8082
.EnableHttpPipelining()
8183
.EnableHttpCompression()
8284
.ThrowExceptions();
@@ -137,18 +139,20 @@ private async Task WriteDirectlyToESAsBatch(IEnumerable<JObject> jos)
137139
var bb = jos.Zip(indxC, (f, s) => new object[] { s, f });
138140
var bbo = bb.SelectMany(a => a);
139141

140-
try
141-
{
142-
//await Client.BulkPutAsync<VoidResponse>(Index, DocumentType, bbo.ToArray(), br => br.Refresh(false));
143-
await Client.BulkPutAsync<VoidResponse>(Index, DocumentType,
144-
PostData.MultiJson(bbo.ToArray()),
145-
new BulkRequestParameters { Refresh = Refresh.False });
146-
}
147-
catch (Exception)
148-
{
149-
//eat the exception, we cant really do much with it anyways
150-
//Debug.WriteLine(ex.Message);
151-
}
142+
_ = Client.BulkPutAsync<VoidResponse>(Index, DocumentType,
143+
PostData.MultiJson(bbo.ToArray()),
144+
new BulkRequestParameters { Refresh = Refresh.False })
145+
.ContinueWith(x =>
146+
{
147+
if (x.IsFaulted)
148+
{
149+
Debug.WriteLine(x.Exception);
150+
}
151+
},
152+
CancellationToken.None,
153+
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
154+
TaskScheduler.Current);
155+
152156
}
153157

154158
private void WriteToQueueForProcessing(JObject jo)

0 commit comments

Comments
 (0)