Zenith.Extensions.Elasticsearch
1.0.0
dotnet add package Zenith.Extensions.Elasticsearch --version 1.0.0
NuGet\Install-Package Zenith.Extensions.Elasticsearch -Version 1.0.0
<PackageReference Include="Zenith.Extensions.Elasticsearch" Version="1.0.0" />
<PackageVersion Include="Zenith.Extensions.Elasticsearch" Version="1.0.0" />
<PackageReference Include="Zenith.Extensions.Elasticsearch" />
paket add Zenith.Extensions.Elasticsearch --version 1.0.0
#r "nuget: Zenith.Extensions.Elasticsearch, 1.0.0"
#:package Zenith.Extensions.Elasticsearch@1.0.0
#addin nuget:?package=Zenith.Extensions.Elasticsearch&version=1.0.0
#tool nuget:?package=Zenith.Extensions.Elasticsearch&version=1.0.0
Zenith.Extensions.Elasticsearch
Zenith.Extensions.Elasticsearch
A production-grade, high-availability Elasticsearch helper library for .NET, built on the official modern Elastic.Clients.Elasticsearch 9.0+ SDK. This package provides encapsulated synchronous/asynchronous indexing, built-in circuit breaker failure protection, environment-based configuration, socket exhaustion prevention, and automatic service recovery — ready for high-concurrency production logging and document indexing scenarios.
✨ Core Features
Modern Elasticsearch 9.x Support: Fully adapted to the latest official client API and response validation rules
Built-in Circuit Breaker: Rolling 10s failure statistics, automatic trip & 90s cooldown recovery to avoid avalanche failure
Global Singleton Client: Single reusable Elasticsearch client to completely solve socket exhaustion under high QPS
Environment Variable Configuration: Dynamic endpoint loading via
ELASTICSEARCH_URL, with intelligent fallback default valueDual Sync / Async API: Provides both
LogAsyncandLogfor flexible business usageAutomatic Index Normalization: Auto convert index name to lowercase to comply with Elasticsearch 9.x strict rules
Structured Logging Integration: Built-in ILogger error/warning/critical logs for troubleshooting
High Concurrency Safe: Thread-safe failure queue & lock-free state judgment, optimized for heavy traffic
📦 Installation
.NET CLI
dotnet add package Zenith.Extensions.Elasticsearch
NuGet Package Manager
Install-Package Zenith.Extensions.Elasticsearch
⚙️ Environment Configuration
The library automatically reads the Elasticsearch connection address from environment variables:
Key:
ELASTICSEARCH_URLDefault fallback:
http://localhost:9200Request Timeout: Fixed 2 seconds for fast failure response
🚀 DI Integration (ASP.NET Core)
Standard dependency injection registration with logger support:
// Program.cs
builder.Services.AddScoped<ElasticSearchHelper>(sp =>
{
var logger = sp.GetService<ILogger<ElasticSearchHelper>>();
return new ElasticSearchHelper(logger);
});
📝 Usage Examples
Asynchronous Indexing (Recommended)
public class LogService
{
private readonly ElasticSearchHelper _esHelper;
public LogService(ElasticSearchHelper esHelper)
{
_esHelper = esHelper;
}
public async Task WriteLogAsync()
{
var logModel = new
{
Message = "System running log",
CreateTime = DateTime.UtcNow,
Level = "Info"
};
// Index name will auto convert to lowercase
await _esHelper.LogAsync("system-log", logModel);
}
}
Synchronous Indexing
_esHelper.Log("business-log", new { OrderId = 10001, Status = "Success" });
🛡️ Built-in Circuit Breaker Mechanism
This library implements a rolling window circuit breaker to protect downstream Elasticsearch clusters in high-concurrency scenarios:
Trigger Rule: Trip circuit if 3 failures occur within 10 seconds
Protection Duration: 90 seconds cooling window
Auto Recovery: Automatically close circuit and resume traffic after cooldown
Failure Isolation: Reject new requests actively to prevent service avalanche
📚 API Reference
LogAsync<T>(string index, T data)Asynchronously write generic document data to specified indexLog<T>(string index, T data)Synchronously write generic document data to specified index
🔧 Supported Frameworks & Dependencies
Target Frameworks: .NET 6 / .NET 7 / .NET 8 / .NET 9+
Core Dependency: Elastic.Clients.Elasticsearch 9.0+
Logging: Microsoft.Extensions.Logging
💡 Production Best Practices
Set
ELASTICSEARCH_URLenvironment variable in staging/production environmentsPrefer async
LogAsyncin web applications to improve throughputLeverage built-in circuit breaker to avoid massive error cascades during ES cluster downtime
Reuse helper instance via DI to maintain singleton ES client connection
📄 License
Open-source library for commercial and non-commercial use. Free to reference, extend and optimize.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Elastic.Clients.Elasticsearch (>= 9.4.2)
- log4net (>= 3.3.2)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.9)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 88 | 7/11/2026 |
ElasticSearch Logging Library initial release.