diff --git a/.editorconfig b/.editorconfig
index 9bdbb34e..5ae50828 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -6,3 +6,19 @@ indent_size = 4
[*.csproj]
indent_size = 2
+
+# Code files
+[*.{cs,csx,vb,vbx}]
+###############################
+# Naming Conventions #
+###############################
+# Underscore for private fields
+dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
+dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
+dotnet_naming_rule.private_members_with_underscore.severity = suggestion
+
+dotnet_naming_symbols.private_fields.applicable_kinds = field
+dotnet_naming_symbols.private_fields.applicable_accessibilities = private
+
+dotnet_naming_style.prefix_underscore.capitalization = camel_case
+dotnet_naming_style.prefix_underscore.required_prefix = _
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..79b78fec
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,16 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+ - package-ecosystem: "nuget"
+ directory: "/" # Location of package manifests
+ schedule:
+ interval: "daily"
+
+ - package-ecosystem: "github-actions"
+ directory: "/" # Location of package manifests
+ schedule:
+ interval: "daily"
\ No newline at end of file
diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml
new file mode 100644
index 00000000..06f22817
--- /dev/null
+++ b/.github/workflows/cicd.yaml
@@ -0,0 +1,150 @@
+name: Continuous Integration
+
+on:
+ push:
+ pull_request:
+ release:
+ types:
+ - published
+env:
+ Configuration: Release
+ ContinuousIntegrationBuild: true
+ DOTNET_CLI_TELEMETRY_OPTOUT: true
+ DOTNET_NOLOGO: true
+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
+
+ # GitHub Packages Feed settings
+ GITHUB_FEED: https://nuget.pkg.github.com/serilog-contrib/
+ GITHUB_USER: mivano
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+jobs:
+ package:
+ runs-on: ubuntu-latest
+ name: Run tests and create NuGet package
+ outputs:
+ coverage-reports: ${{ steps.dotnet-test.outputs.coverage-reports }}
+ version: ${{ steps.dotnet-pack.outputs.version }}
+ nupkg-filename: ${{ steps.dotnet-pack.outputs.nupkg-filename }}
+ release-body: ${{ steps.tag-message.outputs.release-notes }}
+ steps:
+ - name: Checkout git repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+
+ - name: Install .NET SDK
+ uses: actions/setup-dotnet@v3.0.3
+ with:
+ dotnet-version: '7.0.x'
+
+ - name: Retrieve cached NuGet packages
+ uses: actions/cache@v3
+ with:
+ path: ~/.nuget/packages
+ key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
+
+ - name: Restore NuGet packages
+ run: dotnet restore
+
+ - name: Build solution
+ run: dotnet build --no-restore -c Release
+
+ - name: Run tests
+ run: dotnet test --no-build -c Release --logger "html;LogFileName=TestResults-${{ runner.os }}.html" --logger "trx;LogFileName=TestResults-${{ runner.os }}.trx" --logger GitHubActions
+ id: dotnet-test
+
+ - name: Upload received files from failing tests
+ uses: actions/upload-artifact@v3
+ if: failure()
+ with:
+ name: Received-${{ runner.os }}
+ path: "**/*.received.*"
+
+ - name: Upload test results
+ uses: actions/upload-artifact@v3
+ if: always()
+ with:
+ name: TestResults-${{ runner.os }}
+ path: test/Serilog.Sinks.Elasticsearch.Tests/TestResults/TestResults-${{ runner.os }}.html
+
+ - name: Test Report
+ uses: dorny/test-reporter@v1
+ if: always()
+ with:
+ name: Test Results (${{ runner.os }})
+ path: '**.trx'
+ reporter: dotnet-trx
+
+ - name: Create NuGet packages
+ run: dotnet pack --no-build -c Release --version-suffix "ci-$GITHUB_RUN_ID" --include-symbols --include-source --output .
+ id: dotnet-pack
+
+ - name: Upload NuGet package artifact
+ uses: actions/upload-artifact@v3
+ with:
+ name: nuget
+ path: '**/*.nupkg'
+
+ prerelease:
+ needs: package
+ name: Create prerelease
+ if: github.ref == 'refs/heads/dev'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Download Artifact
+ uses: actions/download-artifact@v3
+ with:
+ name: nuget
+ path: nuget
+ - name: Push to GitHub Feed
+ run: |
+ dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json"
+
+ for f in ./nuget/*.nupkg
+ do
+ echo $f
+ dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
+ done
+
+ publish:
+ runs-on: ubuntu-latest
+ needs: package
+ if: github.event_name == 'release'
+ name: Publish NuGet package
+ steps:
+ - name: Checkout git repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+
+ - name: Install .NET SDK
+ uses: actions/setup-dotnet@v3.0.3
+
+ - name: Retrieve cached NuGet packages
+ uses: actions/cache@v3
+ with:
+ path: ~/.nuget/packages
+ key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
+
+ - name: Restore NuGet packages
+ run: dotnet restore
+
+ - name: Create Release NuGet package
+ run: |
+ arrTag=(${GITHUB_REF//\// })
+ VERSION="${arrTag[2]}"
+ VERSION="${VERSION//v}"
+ dotnet pack -v normal -c Release --include-symbols --include-source -p:Version=$VERSION -o ./nuget
+
+ - name: Push to GitHub Feed
+ run: |
+ dotnet nuget add source --username $GITHUB_USER --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json"
+
+ for f in ./nuget/*.nupkg
+ do
+ dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
+ done
+
+ - name: Publish NuGet package on nuget.org
+ run: dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_API_KEY }}" --skip-duplicate
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..ceb06dd7
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,73 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+# ******** NOTE ********
+
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ dev, master ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ dev ]
+ schedule:
+ - cron: '27 7 * * 6'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [ 'csharp' ]
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
+ # Learn more...
+ # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ - name: Setup dotnet
+ uses: actions/setup-dotnet@v3.0.3
+ with:
+ dotnet-version: '6.0.x'
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v2
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 41fffdd6..01d05bc1 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -1,16 +1,21 @@
{
- "version": "0.1.0",
+ "version": "2.0.0",
"command": "dotnet",
- "isShellCommand": true,
"args": [],
"tasks": [
{
- "taskName": "build",
+ "label": "build",
+ "type": "shell",
+ "command": "dotnet",
"args": [
+ "build",
"${workspaceRoot}/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj"
],
- "isBuildCommand": true,
- "problemMatcher": "$msCompile"
+ "problemMatcher": "$msCompile",
+ "group": {
+ "_id": "build",
+ "isDefault": false
+ }
}
]
}
\ No newline at end of file
diff --git a/.vscode/tasks.json.old b/.vscode/tasks.json.old
new file mode 100644
index 00000000..41fffdd6
--- /dev/null
+++ b/.vscode/tasks.json.old
@@ -0,0 +1,16 @@
+{
+ "version": "0.1.0",
+ "command": "dotnet",
+ "isShellCommand": true,
+ "args": [],
+ "tasks": [
+ {
+ "taskName": "build",
+ "args": [
+ "${workspaceRoot}/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj"
+ ],
+ "isBuildCommand": true,
+ "problemMatcher": "$msCompile"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Build.ps1 b/Build.ps1
deleted file mode 100644
index 044678db..00000000
--- a/Build.ps1
+++ /dev/null
@@ -1,52 +0,0 @@
-echo "In directory: $PSScriptRoot"
-
-$solution = "serilog-sinks-elasticsearch.sln"
-$test = "test\\Serilog.Sinks.Elasticsearch.Tests\\Serilog.Sinks.Elasticsearch.Tests.csproj"
-$testIntegration = "test\\Serilog.Sinks.Elasticsearch.IntegrationTests\\Serilog.Sinks.Elasticsearch.IntegrationTests.csproj"
-[string[]]$projects = @(
- ("src\\Serilog.Sinks.Elasticsearch\\Serilog.Sinks.Elasticsearch.csproj"),
- ("src\\Serilog.Formatting.Elasticsearch\\Serilog.Formatting.Elasticsearch.csproj")
-)
-
-function Invoke-Build()
-{
- Write-Output "Building"
-
- if(Test-Path .\artifacts) {
- echo "build: Cleaning .\artifacts"
- Remove-Item .\artifacts -Force -Recurse
- }
-
- & dotnet test $test -c Release
- if($LASTEXITCODE -ne 0)
- {
- Write-Output "The tests failed"
- exit 1
- }
-
- Write-Output "Running integration tests"
- # Tee-Object forces console redirection on vstest which magically makes Console.WriteLine works again.
- # This allows you to see the console out of Elastic.Xunit while its running
- & dotnet test $testIntegration -c Release | Tee-Object -Variable integ
- if($LASTEXITCODE -ne 0)
- {
- Write-Output "The integration tests failed"
- exit 1
- }
-
- Write-Output "Creating packages"
- foreach ($project in $projects)
- {
- & dotnet pack $project -c Release -o ..\..\artifacts -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg /p:PackageVersion=$env:GitVersion_NuGetVersionV2
- }
-
- if($LASTEXITCODE -ne 0)
- {
- Write-Output "Packing the sink failed"
- exit 1
- }
- Write-Output "Building done"
-}
-
-$ErrorActionPreference = "Stop"
-Invoke-Build
diff --git a/CHANGES.md b/CHANGES.md
index 8e94e8a9..662ea84e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,7 +6,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [9.0.0] - 2023-01-23
+### Added
+ - PR #462
+ - PR #488
+
+### Major Changes
+- `DetectElasticsearchVersion` is set to `true` by default.
+- When `DetectElasticsearchVersion` is set to `false` Elasticsearch version 7 is assumed (as it has broadest wire-compatibility at the moment - v7 and v8)
+- When `DetectElasticsearchVersion` is set to `true`, `TypeName` is handled automatically across different versions of Elasticserach (6.x to 8.x). For example, user-defined name will NOT be used on v7 and v8. Also, correct templates endpoint will be picked up.
+- Elasticsearch 8.x endpoint for templates is supported (`_index_template`)
+- Internal class `ElasticsearchVersionManager` has been added, mainly to handle situations where detection of version fails or when it is disabled. In the case of fallback, sink will assume "default" version 7.
+- Elasticsearch.NET client version 7.15.2 (latest version 7, until new `Elastic.Clients.Elasticsearch` 8.x catches up functional parity with 7.x).
+- Elasticsearch server versions 2 and 5 are no longer supported.
+
+### Other Changes
+- Nuget pacakges have been updated (except for the Elasticsearch integration-tests related packages)
+- Most of the `ElasticserachSink` functionality has been moved into internal `BatchedElasticsearchSink` class that inherits from `IBatchedLogEventSink`, so it complies with new recommended way of integration with `PeriodicBatchingSink` and we don't use obsolete constructors.
+- `ConnectionStub` was moved out of `ElasticsearchSinkTestsBase` and extended. Both are now in `/Stubs` subfolder. Newer versions of Elasticsearch.NET client are now using "pre-flight" request to determine if endpoint is Elasticsearch and if it is indeed between 6.x and 8.x. `ConnectionStub` had to accommodate for that.
+- Unit tests have been fixed/added accordingly, running on multiple target frameworks (`net6`, `net7` and `net48`).
+- Built-in .NET SDK conditional compilation symbols are now used (e.g NETFRAMEWORK).
+
+## [9.0.0] - 2022-04-29
+
+### Fixed
+ - Dropped support for old .NET framework, and now uses .NET Core. Previous versions were out of support by MS anyway.
+ - Fixed the build so it uses GitHub Actions as AppVeyor was not working
+ - Created packages in GitHub Packages
+
+### Added
+ - PR #420
+ - PR #416
+ - PR #406
## [8.4.1] - 2020-09-28
### Fixed
- Make sure TypeName is set to `_doc` when setting the template version to `ESv7`.
diff --git a/README.md b/README.md
index e2c0a240..65f12f3f 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Serilog.Sinks.Elasticsearch [![Build status](https://ci.appveyor.com/api/projects/status/bk367tcnx9qt2sjy/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-elasticsearch/branch/master) [![NuGet Badge](https://img.shields.io/nuget/v/Serilog.Sinks.Elasticsearch.svg)](https://www.nuget.org/packages/Serilog.Sinks.Elasticsearch)
+# Serilog.Sinks.Elasticsearch [![Continuous Integration](https://github.com/serilog-contrib/serilog-sinks-elasticsearch/actions/workflows/cicd.yaml/badge.svg?branch=dev)](https://github.com/serilog-contrib/serilog-sinks-elasticsearch/actions/workflows/cicd.yaml) [![NuGet Badge](https://img.shields.io/nuget/v/Serilog.Sinks.Elasticsearch.svg)](https://www.nuget.org/packages/Serilog.Sinks.Elasticsearch)
This repository contains two nuget packages: `Serilog.Sinks.Elasticsearch` and `Serilog.Formatting.Elasticsearch`.
@@ -30,6 +30,7 @@ The Serilog Elasticsearch sink project is a sink (basically a writer) for the Se
* Starting from version 3, compatible with Elasticsearch 2.
* Version 6.x supports the new Elasticsearch.net version 6.x library.
* From version 8.x there is support for Elasticsearch.net version 7.
+* From version 9.x there is support for Elasticsearch.net version 8. Version detection is enabled by default, in which case `TypeName` is handled automatically across major versions 6, 7 and 8. Versions 2 and 5 of Elasticsearch are no longer supported. Version 9.0.0 of the sink targets netstandard2.0 and therefore can be run on any .NET Framework that supports it (both .NET Core and .NET Framework), however, we are focused on testing it with .NET 6.0 to make the maintenance simpler.
## Quick start
@@ -40,16 +41,80 @@ The Serilog Elasticsearch sink project is a sink (basically a writer) for the Se
Install-Package serilog.sinks.elasticsearch
```
-Register the sink in code or using the appSettings reader (from v2.0.42+) as shown below. Make sure to specify the version of ES you are targeting. Be aware that the AutoRegisterTemplate option will not overwrite an existing template.
+Simplest way to register this sink is to use default configuration:
+
+```csharp
+var loggerConfig = new LoggerConfiguration()
+ .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200")));
+```
+
+Or, if using .NET Core and `Serilog.Settings.Configuration` Nuget package and `appsettings.json`, default configuration would look like this:
+
+```json
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.Elasticsearch" ],
+ "MinimumLevel": "Warning",
+ "WriteTo": [
+ {
+ "Name": "Elasticsearch",
+ "Args": {
+ "nodeUris": "http://localhost:9200"
+ }
+ }
+ ],
+ "Enrich": [ "FromLogContext", "WithMachineName" ],
+ "Properties": {
+ "Application": "ImmoValuation.Swv - Web"
+ }
+ }
+}
+```
+
+More elaborate configuration, using additional Nuget packages (e.g. `Serilog.Enrichers.Environment`) would look like:
+
+```json
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.Elasticsearch" ],
+ "MinimumLevel": "Warning",
+ "WriteTo": [
+ {
+ "Name": "Elasticsearch",
+ "Args": {
+ "nodeUris": "http://localhost:9200"
+ }
+ }
+ ],
+ "Enrich": [ "FromLogContext", "WithMachineName" ],
+ "Properties": {
+ "Application": "My app"
+ }
+ }
+}
+```
+
+This way the sink will detect version of Elasticsearch server (`DetectElasticsearchVersion` is set to `true` by default) and handle `TypeName` behavior correctly, based on the server version (6.x, 7.x or 8.x).
+
+### Disable detection of Elasticsearch server version
+
+Alternatively, `DetectElasticsearchVersion` can be set to `false` and certain option can be configured manually. In that case, the sink will assume version 7 of Elasticsearch, but options will be ignored due to a potential version incompatibility.
+
+For example, you can configure the sink to force registeration of v6 index template. Be aware that the AutoRegisterTemplate option will not overwrite an existing template.
```csharp
var loggerConfig = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200") ){
+ DetectElasticsearchVersion = false,
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6
});
```
+### Configurable properties
+
+Besides a registration of the sink in the code, it is possible to register it using appSettings reader (from v2.0.42+) reader (from v2.0.42+) as shown below.
+
This example shows the options that are currently available when using the appSettings reader.
```xml
@@ -75,7 +140,8 @@ This example shows the options that are currently available when using the appSe
-
+
+
@@ -278,6 +344,10 @@ Option BufferFileSizeLimitBytes is added The maximum size, in bytes, to which th
### Breaking changes
+#### Version 9
+
+* Dropped support for 456 and sticking now with NETSTANDARD
+
#### Version 7
* Nuget Serilog.Sinks.File is now used instead of deprecated Serilog.Sinks.RollingFile
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 66f4f1dd..00000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-version: '{build}'
-image: Visual Studio 2017
-skip_tags: true
-build_script:
-- ps: ./Build.ps1
-test: off
-artifacts:
- - path: artifacts/Serilog.Sinks.Elasticsearch*.*nupkg
- - path: artifacts/Serilog.Formatting.Elasticsearch*.*nupkg
-only_commits:
- files:
- - serilog-sinks-elasticsearch.sln
- - src/Serilog.Sinks.Elasticsearch/
- - src/Serilog.Formatting.Elasticsearch/
- - nuget.config
- - Build.ps1
- - assets/
- - appveyor.yml
- - test/Serilog.Sinks.Elasticsearch.Tests/
-deploy:
-- provider: NuGet
- api_key:
- secure: jWslQvxA4UMn98aYnsFDBfl8A2vAXUjtmmPZNxZnbJvMW/JV55iQ1fRcqD9B70sK
- on:
- branch: /^(master|dev)$/
-- provider: GitHub
- auth_token:
- secure: XSO0LDYd89yw5rAQ8HvAgdX7NBo1m4bEqHlj0NZxtA6zKunLwCSYoVHU+k3cvQIP
- on:
- branch: master
- artifact: /Serilog.*\.nupkg/
- tag: v$(appveyor_build_version)
-install:
- - choco install gitversion.portable -y
-assembly_info:
- patch: false
-before_build:
- - dotnet restore serilog-sinks-elasticsearch.sln
- - ps: gitversion /l console /output buildserver /updateAssemblyInfo
\ No newline at end of file
diff --git a/assets/serilog-sink-nuget.png b/assets/serilog-sink-nuget.png
new file mode 100644
index 00000000..a77d65c4
Binary files /dev/null and b/assets/serilog-sink-nuget.png differ
diff --git a/global.json b/global.json
deleted file mode 100644
index 99d2533c..00000000
--- a/global.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "sdk": {
- "version": "2.1.807"
- }
-}
\ No newline at end of file
diff --git a/nuget.config b/nuget.config
index a81fc3ec..81b3d073 100644
--- a/nuget.config
+++ b/nuget.config
@@ -8,8 +8,7 @@
-
-
+
diff --git a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs
index b8640806..765d0c86 100644
--- a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs
+++ b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs
@@ -4,8 +4,6 @@
using System.Reflection.Metadata.Ecma335;
using System.Threading;
using Microsoft.Extensions.Configuration;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using Serilog;
using Serilog.Core;
using Serilog.Debugging;
diff --git a/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj b/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj
index 20f60c18..2e04d39f 100644
--- a/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj
+++ b/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj
@@ -2,16 +2,17 @@
Exe
- netcoreapp2.1
+ net6.0
+ false
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/serilog-sinks-elasticsearch.sln b/serilog-sinks-elasticsearch.sln
index 50f5d5d2..f36d10e7 100644
--- a/serilog-sinks-elasticsearch.sln
+++ b/serilog-sinks-elasticsearch.sln
@@ -5,15 +5,12 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{148431F6-5BA9-4987-80CF-DF9F23F54947}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
- .gitattributes = .gitattributes
+ .gitattributes = .gitattributes
.gitignore = .gitignore
- appveyor.yml = appveyor.yml
- Build.ps1 = Build.ps1
CHANGES.md = CHANGES.md
LICENSE = LICENSE
nuget.config = nuget.config
README.md = README.md
- global.json = global.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Elasticsearch", "src\Serilog.Sinks.Elasticsearch\Serilog.Sinks.Elasticsearch.csproj", "{EEB0D119-687E-444E-BF14-9BDAEC9BA3EF}"
diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec
deleted file mode 100644
index 88c88466..00000000
--- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- Serilog.Formatting.Elasticsearch
- $version$
- Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe
- The perfect way for .NET apps formatting structured log events to Elasticsearch JSON. This package contains the formatter used for the Elasticsearch Sink.
- en-US
- http://serilog.net
- http://www.apache.org/licenses/LICENSE-2.0
- http://serilog.net/images/serilog-sink-nuget.png
- serilog logging elasticsearch
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec
deleted file mode 100644
index 50f0444a..00000000
--- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- Serilog.Formatting.Elasticsearch
- $version$
- Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Konstantin Erman
- The perfect way for .NET apps formatting structured log events to Elasticsearch JSON. This package contains the formatter used for the Elasticsearch Sink.
- en-US
- http://serilog.net
- http://www.apache.org/licenses/LICENSE-2.0
- http://serilog.net/images/serilog-sink-nuget.png
-
- serilog logging elasticsearch formatters
-
-
-
-
-
-
-
-
diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj
index 7bab4bfc..e9bf5713 100644
--- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj
+++ b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj
@@ -1,44 +1,37 @@
-
- 6.0.0
- alpha
Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Serilog Contributors
- net45;netstandard1.3;netstandard2.0
+ Serilog.Sinks.Elasticsearch
+ Serilog sink for Elasticsearch
+ Copyright © Serilog Contributors 2023
+
+
+
+ netstandard2.0
true
true
Serilog.Formatting.Elasticsearch
../../assets/Serilog.snk
true
- true
+ false
Serilog.Formatting.Elasticsearch
serilog;elasticsearch;logging;event;formatting
- https://github.com/serilog/serilog-sinks-elasticsearch/blob/master/CHANGES.md
- http://serilog.net/images/serilog-sink-nuget.png
- https://github.com/serilog/serilog-sinks-elasticsearch
- http://www.apache.org/licenses/LICENSE-2.0
- https://github.com/serilog/serilog-sinks-elasticsearch
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch/blob/master/CHANGES.md
+ serilog-sink-nuget.png
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch
+ Apache-2.0
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch
git
- 1.6.1
- false
- false
- false
- false
- false
- false
Serilog.Formatting.ElasticSearch
-
+
-
-
- $(DefineConstants);NO_SERIALIZATION
-
-
+
-
+
+
-
+
diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs
index 7e3ec182..aff44145 100644
--- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs
+++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs
@@ -70,7 +70,7 @@ public static LoggerConfiguration Elasticsearch(
/// Overload to allow basic configuration through AppSettings.
///
/// Options for the sink.
- /// A comma or semi column separated list of URIs for Elasticsearch nodes.
+ /// A comma or semi-colon separated list of URIs for Elasticsearch nodes.
///
///
///
@@ -82,7 +82,7 @@ public static LoggerConfiguration Elasticsearch(
///
///
///
- /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request
+ /// A comma or semi-colon separated list of key value pairs of headers to be added to each elastic http request
[Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration Elasticsearch(
this LoggerSinkConfiguration loggerSinkConfiguration,
@@ -102,14 +102,14 @@ public static LoggerConfiguration Elasticsearch(
{
return Elasticsearch(loggerSinkConfiguration, nodeUris, indexFormat, templateName, typeName, batchPostingLimit, period, inlineFields, restrictedToMinimumLevel, bufferBaseFilename,
bufferFileSizeLimitBytes, bufferLogShippingInterval, connectionGlobalHeaders, levelSwitch, 5, EmitEventFailureHandling.WriteToSelfLog, 100000, null, false,
- AutoRegisterTemplateVersion.ESv2, false, RegisterTemplateRecovery.IndexAnyway, null, null, null);
+ AutoRegisterTemplateVersion.ESv7, false, RegisterTemplateRecovery.IndexAnyway, null, null, null);
}
///
/// Overload to allow basic configuration through AppSettings.
///
/// Options for the sink.
- /// A comma or semi column separated list of URIs for Elasticsearch nodes.
+ /// A comma or semi-colon separated list of URIs for Elasticsearch nodes.
///
///
///
@@ -122,7 +122,7 @@ public static LoggerConfiguration Elasticsearch(
///
///
///
- /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request
+ /// A comma or semi-colon separated list of key value pairs of headers to be added to each elastic http request
/// The connection timeout (in seconds) when sending bulk operations to elasticsearch (defaults to 5).
/// Specifies how failing emits should be handled.
/// The maximum number of events that will be held in-memory while waiting to ship them to Elasticsearch. Beyond this limit, events will be dropped. The default is 100,000. Has no effect on durable log shipping.
@@ -143,6 +143,7 @@ public static LoggerConfiguration Elasticsearch(
/// Sink to use when Elasticsearch is unable to accept the events. This is optionally and depends on the EmitEventFailure setting.
/// The maximum length of an event allowed to be posted to Elasticsearch.default null
/// Add custom elasticsearch settings to the template
+ /// Turns on detection of elasticsearch version via background HTTP call. This will also set `TypeName` automatically, according to the version of Elasticsearch.
/// Configures the OpType being used when inserting document in batch. Must be set to create for data streams.
/// LoggerConfiguration object
/// is .
@@ -151,7 +152,7 @@ public static LoggerConfiguration Elasticsearch(
string nodeUris,
string indexFormat = null,
string templateName = null,
- string typeName = "logevent",
+ string typeName = null,
int batchPostingLimit = 50,
int period = 2,
bool inlineFields = false,
@@ -166,7 +167,7 @@ public static LoggerConfiguration Elasticsearch(
int queueSizeLimit = 100000,
string pipelineName = null,
bool autoRegisterTemplate = false,
- AutoRegisterTemplateVersion autoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv2,
+ AutoRegisterTemplateVersion? autoRegisterTemplateVersion = null,
bool overwriteTemplate = false,
RegisterTemplateRecovery registerTemplateFailure = RegisterTemplateRecovery.IndexAnyway,
string deadLetterIndexName = null,
@@ -182,7 +183,8 @@ public static LoggerConfiguration Elasticsearch(
long? singleEventSizePostingLimit = null,
int? bufferFileCountLimit = null,
Dictionary templateCustomSettings = null,
- ElasticOpType batchAction = ElasticOpType.Index)
+ ElasticOpType batchAction = ElasticOpType.Index,
+ bool detectElasticsearchVersion = true)
{
if (string.IsNullOrEmpty(nodeUris))
throw new ArgumentNullException(nameof(nodeUris), "No Elasticsearch node(s) specified.");
@@ -204,11 +206,6 @@ public static LoggerConfiguration Elasticsearch(
options.TemplateName = templateName;
}
- if (!string.IsNullOrWhiteSpace(typeName))
- {
- options.TypeName = typeName;
- }
-
options.BatchPostingLimit = batchPostingLimit;
options.BatchAction = batchAction;
options.SingleEventSizePostingLimit = singleEventSizePostingLimit;
@@ -275,6 +272,8 @@ public static LoggerConfiguration Elasticsearch(
options.TemplateCustomSettings = templateCustomSettings;
+ options.DetectElasticsearchVersion = detectElasticsearchVersion;
+
return Elasticsearch(loggerSinkConfiguration, options);
}
}
diff --git a/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs
deleted file mode 100644
index c5f05dfe..00000000
--- a/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-[assembly: AssemblyTitle("Serilog.Sinks.Elasticsearch")]
-[assembly: AssemblyDescription("Serilog sink for Elasticsearch")]
-[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2018")]
-
-[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
- "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" +
- "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" +
- "94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" +
- "b19485ec")]
-[assembly: AssemblyVersion("6.0.0.0")]
-[assembly: AssemblyInformationalVersion("6.0.0-unstable.32+Branch.dev.Sha.7e77498e8afaaec96b508de3e8ec6bd3891b3556")]
-[assembly: AssemblyFileVersion("6.0.0.0")]
diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec
deleted file mode 100644
index 9932b8fb..00000000
--- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- Serilog.Sinks.Elasticsearch
- $version$
- Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe
- The perfect way for .NET apps to write structured log events to Elasticsearch.
- en-US
- http://serilog.net
- http://www.apache.org/licenses/LICENSE-2.0
- http://serilog.net/images/serilog-sink-nuget.png
- serilog logging elasticsearch
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec
deleted file mode 100644
index c6ba9cc7..00000000
--- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
- Serilog.Sinks.Elasticsearch
- $version$
- Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Konstantin Erman
- The perfect way for .NET apps to write structured log events to Elasticsearch.
- en-US
- http://serilog.net
- http://www.apache.org/licenses/LICENSE-2.0
- http://serilog.net/images/serilog-sink-nuget.png
-
- serilog logging elasticsearch
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
index 96b1af35..a1f4e2bf 100644
--- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
+++ b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
@@ -1,31 +1,27 @@
-
- 6.0.0
- alpha
Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Serilog Contributors
- net461;netstandard2.0
+ Serilog.Sinks.Elasticsearch
+ Serilog sink for Elasticsearch
+ Copyright © Serilog Contributors 2023
+
+
+ netstandard2.0
true
+ latest
true
Serilog.Sinks.Elasticsearch
../../assets/Serilog.snk
true
- true
+ false
Serilog.Sinks.Elasticsearch
serilog;elasticsearch;logging;event;collector
- https://github.com/serilog/serilog-sinks-elasticsearch/blob/master/CHANGES.md
- http://serilog.net/images/serilog-sink-nuget.png
- https://github.com/serilog/serilog-sinks-elasticsearch
- http://www.apache.org/licenses/LICENSE-2.0
- https://github.com/serilog/serilog-sinks-elasticsearch
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch/blob/master/CHANGES.md
+ serilog-sink-nuget.png
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch
+ https://github.com/serilog-contrib/serilog-sinks-elasticsearch
+ Apache-2.0
git
- 1.6.1
- false
- false
- false
- false
- false
- false
@@ -33,26 +29,28 @@
$(DefineConstants);DURABLE;THREADING_TIMER
-
- 1591;1701;1702
- $(DefineConstants);DURABLE;THREADING_TIMER;HRESULTS
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+ <_Parameter1>Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec
+
+
+
+
+
+
+
diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs
index 45c1da86..60377935 100644
--- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs
+++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs
@@ -39,19 +39,17 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options)
throw new ArgumentException("Cannot create the durable ElasticSearch sink without a buffer base file name!");
}
-
_sink = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(_state.DurableFormatter,
options.BufferBaseFilename + FileNameSuffix,
- rollingInterval: RollingInterval.Day,
+ rollingInterval: options.BufferFileRollingInterval,
fileSizeLimitBytes: options.BufferFileSizeLimitBytes,
rollOnFileSizeLimit: true,
retainedFileCountLimit: options.BufferFileCountLimit,
levelSwitch: _state.Options.LevelSwitch,
encoding: Encoding.UTF8)
.CreateLogger();
-
var elasticSearchLogClient = new ElasticsearchLogClient(
elasticLowLevelClient: _state.Client,
@@ -63,7 +61,8 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options)
typeName:_state.Options.TypeName,
serialize:_state.Serialize,
getIndexForEvent: _state.GetBufferedIndexForEvent,
- elasticOpType: _state.Options.BatchAction);
+ elasticOpType: _state.Options.BatchAction,
+ rollingInterval: options.BufferFileRollingInterval);
_shipper = new ElasticsearchLogShipper(
bufferBaseFilename: _state.Options.BufferBaseFilename,
@@ -75,7 +74,8 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options)
payloadReader: payloadReader,
retainedInvalidPayloadsLimitBytes: _state.Options.BufferRetainedInvalidPayloadsLimitBytes,
bufferSizeLimitBytes: _state.Options.BufferFileSizeLimitBytes,
- registerTemplateIfNeeded: _state.RegisterTemplateIfNeeded);
+ registerTemplateIfNeeded: _state.RegisterTemplateIfNeeded,
+ rollingInterval: options.BufferFileRollingInterval);
}
diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs
index b3573e77..609d9590 100644
--- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs
+++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs
@@ -86,7 +86,7 @@ private InvalidResult GetInvalidPayloadAsync(DynamicResponse baseResult, List>
///
///
///
+ ///
public ElasticsearchLogShipper(string bufferBaseFilename, int batchPostingLimit, TimeSpan period,
long? eventBodyLimitBytes, LoggingLevelSwitch levelControlSwitch, ILogClient> logClient,
IPayloadReader> payloadReader, long? retainedInvalidPayloadsLimitBytes,
- long? bufferSizeLimitBytes, Action registerTemplateIfNeeded)
- : base(bufferBaseFilename, batchPostingLimit, period, eventBodyLimitBytes,
- levelControlSwitch, logClient, payloadReader, retainedInvalidPayloadsLimitBytes, bufferSizeLimitBytes)
+ long? bufferSizeLimitBytes, Action registerTemplateIfNeeded, RollingInterval rollingInterval)
+ : base(bufferBaseFilename, batchPostingLimit, period, eventBodyLimitBytes, levelControlSwitch, logClient,
+ payloadReader, retainedInvalidPayloadsLimitBytes, bufferSizeLimitBytes, rollingInterval)
{
_registerTemplateIfNeeded = registerTemplateIfNeeded;
}
diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs
index 21cf022a..73266667 100644
--- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs
+++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs
@@ -17,6 +17,7 @@ public class ElasticsearchPayloadReader: APayloadReader>
private readonly Func