EasyElasticLogger.NETFramework 1.0.8

dotnet add package EasyElasticLogger.NETFramework --version 1.0.8
                    
NuGet\Install-Package EasyElasticLogger.NETFramework -Version 1.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyElasticLogger.NETFramework" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyElasticLogger.NETFramework" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="EasyElasticLogger.NETFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyElasticLogger.NETFramework --version 1.0.8
                    
#r "nuget: EasyElasticLogger.NETFramework, 1.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EasyElasticLogger.NETFramework@1.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyElasticLogger.NETFramework&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=EasyElasticLogger.NETFramework&version=1.0.8
                    
Install as a Cake Tool

EasyElasticLogger.NETFramework

๐Ÿš€๐Ÿš€๐Ÿš€ A simple and easy-to-use Elasticsearch logger designed for .NET Framework applications

<div align="center">

Simple to use | Feature-rich | Production-ready

</div>

โœจโœจ Features

Feature Category Function Description
โœ… Flexible Configuration Supports multiple configuration methods: direct parameters, JSON file, .config file
โœ… Index Strategy Multiple index strategies: fixed index, date-based rolling index, compliant with ELK best practices
โœ… Cluster Support Supports both single-node and cluster modes, with robust connection management
โœ… Log Levels Rich log levels: Debug, Info, Warn, Error, Fatal
โœ… Fault Tolerance Comprehensive fault tolerance and error handling to ensure no log loss
โœ… Performance Optimization Flexible API design, supports both synchronous and asynchronous logging
โœ… Multi-environment Support Supports multi-environment configurations (development, testing, production)
โœ… Strong Compatibility Compatible with AutoCAD secondary development, supports custom configuration file paths
โœ… Easy to Use Designed as a static class, making it simple and intuitive to use

๐ŸŽฏ๐ŸŽฏ Applicable Scenarios

๐Ÿ“ข๐Ÿ“ข Important Note: This plugin is only applicable to .NET Framework 4.7.2 and 4.8 version applications. The Elasticsearch version is compatible with Elasticsearch 7.x

๐Ÿ“Š๐Ÿ“Š Systems that need to centralize logs to ELK for unified analysis

  • Systems requiring real-time log monitoring and alerts
  • Scenarios where you want to leverage Kibana for log visualization and analysis

๐Ÿ–ฅ๏ธ๐Ÿ–ฅ๏ธ Applications based on .NET Framework 4.7.2/4.8

  • WinForm desktop applications (.NET Framework 4.7.2/4.8)
  • WPF desktop applications (.NET Framework 4.7.2/4.8)
  • WebForm traditional web applications (.NET Framework 4.7.2/4.8)
  • Windows services and background task programs (.NET Framework 4.7.2/4.8)
  • Console applications logging needs (.NET Framework 4.7.2/4.8)

๐Ÿ”ง๐Ÿ”ง Diagnostic and operational logging needs in special development environments

  • AutoCAD secondary development plugin logging (based on .NET Framework)
  • Revit and other BIM software plugin development (based on .NET Framework)
  • Industrial software plugin diagnostics and operational monitoring
  • Special environment deployments requiring custom configuration file paths

โŒโŒ Unsupported Scenarios

  • .NET Core / .NET 5/6/7/8 applications
  • .NET Standard class library projects
  • .NET Framework versions below 4.7.2
  • Cross-platform applications (Linux/macOS)

๐Ÿ“ฆ๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

Install-Package EasyElasticLogger.NETFramework
```xml

Or install via .NET CLI:

```bash
dotnet add package EasyElasticLogger.NETFramework
```xml

---

## ๐Ÿš€๐Ÿš€๐Ÿš€ Quick Start

### 1. Basic Usage

```csharp
using EasyElasticLogger.NETFramework.ES.Logging;

// Initialize at application startup (e.g., in Program.cs or Startup.cs)
ElasticLogger.Initialize("Production");

// Use static methods anywhere you need to log
// Synchronous logging
ElasticLogger.Info("This is an info log");
ElasticLogger.Warn("This is a warning log");
ElasticLogger.Error("This is an error log", new Exception("Test exception"));

// Asynchronous logging
await ElasticLogger.InfoAsync("This is an async info log");
await ElasticLogger.ErrorAsync("This is an async error log", new Exception("Test exception"));
```xml

### 2. Environment Configuration

#### Using Environment Variables

```csharp
// Set environment variable
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");

// Or set ENVIRONMENT environment variable
Environment.SetEnvironmentVariable("ENVIRONMENT", "Test");

// Initialize with environment-specific configuration
ElasticLogger.Initialize();
```xml

#### Using Initialization Method to Specify Environment

```csharp
// Directly specify the environment
ElasticLogger.Initialize("Production");
```xml

---

## โš™โš™โš™๏ธ Configuration Methods

Configuration loading priority: **Direct parameters > JSON configuration > .config configuration**

### 1. ๐Ÿ“๐Ÿ“ Direct Parameter Configuration

```csharp
var config = new LoggerConfiguration
{
    Enabled = true,
    IndexPrefix = "myapp-log",
    IndexStrategy = IndexStrategy.DailyRolling,
    ApplicationName = "MyApplication",
    BatchSize = 100,
    TimeoutMs = 10000,
    Cluster = new ClusterConfigurationElement
    {
        Nodes = new List<string> { "http://localhost:9200" },
        Username = "elastic",
        Password = "password",
        UseSsl = false,
        SkipSslVerification = false,
        ConnectionTimeoutMs = 5000,
        MaxRetries = 2
    }
};

ElasticLogger.Initialize(config);
```xml

### 2. ๐Ÿ“„๐Ÿ“„ JSON Configuration File (Supports Environment-Specific Configuration)

```csharp
// Automatically looks for logger-config.Production.json or logger-config.json
ElasticLogger.InitializeFromJson("logger-config.json", "Production");
```xml

#### JSON Configuration File Example

**Default Configuration (logger-config.json)**
```json
{
  "Enabled": true,
  "IndexPrefix": "myapp-log",
  "IndexStrategy": "DailyRolling",
  "ApplicationName": "MyApplication",
  "BatchSize": 100,
  "TimeoutMs": 10000,
  "Cluster": {
    "Nodes": ["http://localhost:9200"],
    "Username": "elastic",
    "Password": "password",
    "UseSsl": false,
    "SkipSslVerification": false,
    "ConnectionTimeoutMs": 5000,
    "MaxRetries": 2
  }
}
```xml

**Production Environment Configuration (logger-config.Production.json)**
```json
{
  "Enabled": true,
  "IndexPrefix": "myapp-log-prod",
  "IndexStrategy": "DailyRolling",
  "ApplicationName": "MyProductionApp",
  "BatchSize": 100,
  "TimeoutMs": 10000,
  "Cluster": {
    "Nodes": ["http://prod-es1:9200", "http://prod-es2:9200", "http://prod-es3:9200"],
    "Username": "elastic",
    "Password": "prod_password",
    "UseSsl": true,
    "SkipSslVerification": false,
    "ConnectionTimeoutMs": 10000,
    "MaxRetries": 3
  }
}
```xml

**Usage Example**
```csharp
// Use default JSON configuration file
ElasticLogger.InitializeFromJson("logger-config.json");

// Use specified environment JSON configuration file
ElasticLogger.InitializeFromJson("logger-config.json", "Production");
```xml

### 3. โš™โš™โš™๏ธ .config Configuration File (Supports Environment-Specific Configuration)

```xml
<configuration>
  <appSettings>
    <add key="Environment" value="Development" />
  </appSettings>
  
  <configSections>
    
    <section name="elasticLogger" type="EasyElasticLogger.NETFramework.ES.Configuration.LoggerConfiguration, EasyElasticLogger.NETFramework" />
    
    
    <section name="elasticLogger.Development" type="EasyElasticLogger.NETFramework.ES.Configuration.LoggerConfiguration, EasyElasticLogger.NETFramework" />
    <section name="elasticLogger.Test" type="EasyElasticLogger.NETFramework.ES.Configuration.LoggerConfiguration, EasyElasticLogger.NETFramework" />
    <section name="elasticLogger.Production" type="EasyElasticLogger.NETFramework.ES.Configuration.LoggerConfiguration, EasyElasticLogger.NETFramework" />
  </configSections>

  
  <elasticLogger enabled="true" indexPrefix="app-log" applicationName="MyApplication" batchSize="100" timeoutMs="10000" indexStrategy="DailyRolling">
    <cluster nodes="http://localhost:9200" username="" password="" useSsl="false" skipSslVerification="false" connectionTimeoutMs="5000" maxRetries="2" />
  </elasticLogger>

  
  <elasticLogger.Development enabled="true" indexPrefix="dev-app-log" applicationName="MyApplication-Dev" batchSize="50" timeoutMs="15000" indexStrategy="DailyRolling">
    <cluster nodes="http://localhost:9200" username="elastic" password="changeme" useSsl="false" skipSslVerification="true" connectionTimeoutMs="10000" maxRetries="3" />
  </elasticLogger.Development>

  
  <elasticLogger.Production enabled="true" indexPrefix="prod-app-log" applicationName="MyApplication-Prod" batchSize="200" timeoutMs="30000" indexStrategy="DailyRolling" fixedIndexName="my-fixed-index">
    <cluster nodes="https://es1.prod.com,https://es2.prod.com,https://es3.prod.com" username="prod-user" password="prod-password" useSsl="true" skipSslVerification="false" connectionTimeoutMs="15000" maxRetries="5" />
  </elasticLogger.Production>
</configuration>
```xml

### 4. ๐Ÿ–ฅ๐Ÿ–ฅ๐Ÿ–ฅ๏ธ Custom Configuration File Path (Compatible with AutoCAD Secondary Development)

```csharp
// Use custom configuration file path and environment for initialization
ElasticLogger.Initialize(@"C:\\MyApp\\config\\myapp.config", "Production");

๐Ÿ“‹๐Ÿ“‹ Logging Examples

Synchronous Logging

``csharp // Debug level log ElasticLogger.Debug("Debug information", "MyClass.Method");

// Info level log ElasticLogger.Info("General information", "MyClass.Method");

// Warn level log ElasticLogger.Warn("Warning information", "MyClass.Method");

// Error level log ElasticLogger.Error("Error information", new Exception("Exception details"), "MyClass.Method");

// Fatal level log ElasticLogger.Fatal("Critical error", new Exception("Exception details"), "MyClass.Method");

// Log with additional data var userData = new { UserId = 123, UserName = "Zhang San" }; ElasticLogger.Info("User login", "UserService.Login", userData);


### Asynchronous Logging

``csharp
// Asynchronously log different levels
await ElasticLogger.DebugAsync("Debug information", "MyClass.Method");
await ElasticLogger.InfoAsync("General information", "MyClass.Method");
await ElasticLogger.WarnAsync("Warning information", "MyClass.Method");
await ElasticLogger.ErrorAsync("Error information", new Exception("Exception details"), "MyClass.Method");
await ElasticLogger.FatalAsync("Critical error", new Exception("Exception details"), "MyClass.Method");

๐Ÿ”ง๐Ÿ”ง Configuration Parameter Details

Logger Configuration Items

Property Type Default Value Description
Enabled bool true Whether to enable the logging feature
IndexPrefix string "app-log" Index prefix
IndexStrategy IndexStrategy DailyRolling Index strategy (Fixed/DailyRolling)
FixedIndexName string null Fixed index name (only used when IndexStrategy is Fixed)
ApplicationName string "DefaultApp" Application name
BatchSize int 100 Batch size for sending logs
TimeoutMs int 10000 Sending timeout in milliseconds

Cluster Configuration Items

Property Type Default Value Description
Nodes List<string> empty List of Elasticsearch node addresses
Username string null Username (for Basic authentication)
Password string null Password (for Basic authentication)
UseSsl bool false Whether to enable SSL
SkipSslVerification bool false Whether to skip SSL certificate verification
ConnectionTimeoutMs int 5000 Connection timeout in milliseconds
MaxRetries int 2 Maximum number of retries

๐Ÿ“Š๐Ÿ“Š Index Strategy

Strategy Description
Fixed Fixed index, all logs are written to the same index
DailyRolling Date-based rolling index, a new index is generated each day (default)

๐Ÿ”„๐Ÿ”„ Environment Configuration Support

Supported Environments

  • ๐Ÿ› ๐Ÿ› ๐Ÿ› ๏ธ Development - Development environment
  • ๐Ÿงช๐Ÿงช๐Ÿงช Test - Testing environment
  • ๐Ÿญ๐Ÿญ๐Ÿญ Production - Production environment

Environment Recognition Priority

  1. ๐Ÿฅ‡๐Ÿฅ‡๐Ÿฅ‡ Environment variable ASPNETCORE_ENVIRONMENT
  2. ๐Ÿฅˆ๐Ÿฅˆ๐Ÿฅˆ Environment variable ENVIRONMENT
  3. ๐Ÿฅ‰๐Ÿฅ‰๐Ÿฅ‰ AppSettings configuration item Environment

๐Ÿ“„๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


<div align="center">

Make logging simple and powerful โœจโœจ

</div>

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.8 110 1/16/2026
1.0.7 96 1/15/2026
1.0.6 215 12/7/2025
1.0.5 204 11/25/2025
1.0.4 188 11/25/2025
1.0.3 413 11/19/2025
1.0.2 282 11/12/2025
1.0.1 288 11/12/2025
1.0.0 297 11/11/2025

## Version 1.0.8

### Performance Improvements
- Enhanced support for .config file configuration
- Improved the LoggerConfiguration class to correctly parse configuration items in .config files
- Added support for nested cluster configurations
- Fixed issues with the serialization and deserialization of configuration properties
- Implemented more flexible environment-specific configuration support