From 4bcce83cc93af74d0dd384418a72d97aebcb8e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Mon, 25 Nov 2024 09:39:25 +0100 Subject: [PATCH 1/7] feat: bump versions to .net 9 --- .nuke/build.schema.json | 137 ++++++++++-------- build/_build.csproj | 9 +- .../MinimalApiSample/MinimalApiSample.csproj | 2 +- samples/WebSample/WebSample.csproj | 2 +- samples/WorkerSample/WorkerSample.csproj | 2 +- ...tility.Extensions.Logging.Dynatrace.csproj | 2 +- ...ty.Extensions.Logging.Elasticsearch.csproj | 2 +- .../Intility.Extensions.Logging.Sentry.csproj | 2 +- .../Intility.Extensions.Logging.csproj | 8 +- .../Intility.Logging.AspNetCore.csproj | 16 +- 10 files changed, 102 insertions(+), 80 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 7eff0f6..4e8d28d 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -1,19 +1,48 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/build", - "title": "Build Schema", "definitions": { - "build": { - "type": "object", + "Host": { + "type": "string", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "ExecutableTarget": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Pack", + "Push", + "Restore" + ] + }, + "Verbosity": { + "type": "string", + "description": "", + "enum": [ + "Verbose", + "Normal", + "Minimal", + "Quiet" + ] + }, + "NukeBuild": { "properties": { - "Configuration": { - "type": "string", - "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", - "enum": [ - "Debug", - "Release" - ] - }, "Continue": { "type": "boolean", "description": "Indicates to continue a previously failed build attempt" @@ -23,38 +52,13 @@ "description": "Shows the help text for this build assembly" }, "Host": { - "type": "string", "description": "Host for execution. Default is 'automatic'", - "enum": [ - "AppVeyor", - "AzurePipelines", - "Bamboo", - "Bitbucket", - "Bitrise", - "GitHubActions", - "GitLab", - "Jenkins", - "Rider", - "SpaceAutomation", - "TeamCity", - "Terminal", - "TravisCI", - "VisualStudio", - "VSCode" - ] + "$ref": "#/definitions/Host" }, "NoLogo": { "type": "boolean", "description": "Disables displaying the NUKE logo" }, - "NugetApiKey": { - "type": "string", - "description": "Api key to use when pushing the package" - }, - "PackageSource": { - "type": "string", - "description": "NuGet artifact target uri - Defaults to https://api.nuget.org/v3/index.json" - }, "Partition": { "type": "string", "description": "Partition to use on CI" @@ -78,45 +82,50 @@ "type": "array", "description": "List of targets to be skipped. Empty list skips all dependencies", "items": { - "type": "string", - "enum": [ - "Clean", - "Compile", - "Pack", - "Push", - "Restore" - ] + "$ref": "#/definitions/ExecutableTarget" } }, - "Solution": { - "type": "string", - "description": "Path to a solution file that is automatically loaded" - }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", "items": { - "type": "string", - "enum": [ - "Clean", - "Compile", - "Pack", - "Push", - "Restore" - ] + "$ref": "#/definitions/ExecutableTarget" } }, "Verbosity": { - "type": "string", "description": "Logging verbosity during build execution. Default is 'Normal'", + "$ref": "#/definitions/Verbosity" + } + } + } + }, + "allOf": [ + { + "properties": { + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", "enum": [ - "Minimal", - "Normal", - "Quiet", - "Verbose" + "Debug", + "Release" ] + }, + "NugetApiKey": { + "type": "string", + "description": "Api key to use when pushing the package" + }, + "PackageSource": { + "type": "string", + "description": "NuGet artifact target uri - Defaults to https://api.nuget.org/v3/index.json" + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" } } + }, + { + "$ref": "#/definitions/NukeBuild" } - } + ] } diff --git a/build/_build.csproj b/build/_build.csproj index de39b71..893db0e 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 CS0649;CS0169 .. @@ -11,8 +11,11 @@ - - + + + + + diff --git a/samples/MinimalApiSample/MinimalApiSample.csproj b/samples/MinimalApiSample/MinimalApiSample.csproj index 3f026a3..f2bef9e 100644 --- a/samples/MinimalApiSample/MinimalApiSample.csproj +++ b/samples/MinimalApiSample/MinimalApiSample.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/samples/WebSample/WebSample.csproj b/samples/WebSample/WebSample.csproj index 2d83485..0bd9a48 100644 --- a/samples/WebSample/WebSample.csproj +++ b/samples/WebSample/WebSample.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 diff --git a/samples/WorkerSample/WorkerSample.csproj b/samples/WorkerSample/WorkerSample.csproj index 27ef004..5650303 100644 --- a/samples/WorkerSample/WorkerSample.csproj +++ b/samples/WorkerSample/WorkerSample.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 dotnet-WorkerSample-E1FD34C8-B239-4D87-8143-0BA5129DDB52 diff --git a/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj b/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj index 927d22b..05d86ac 100644 --- a/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj +++ b/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 diff --git a/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj b/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj index aa06e33..db8eef2 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj +++ b/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 diff --git a/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj b/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj index 742373d..29ae2d9 100644 --- a/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj +++ b/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 diff --git a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj index 0d025c6..2fabd07 100644 --- a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj +++ b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 @@ -20,7 +20,7 @@ - + @@ -35,6 +35,10 @@ + + + + diff --git a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj index 8060ce1..5e697f0 100644 --- a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj +++ b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 @@ -24,7 +24,7 @@ - + @@ -43,10 +43,16 @@ - + - - + + + + + + + + From 3b8d8b5b507e179baebe6917af2877ce6eaaf01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Mon, 25 Nov 2024 09:53:11 +0100 Subject: [PATCH 2/7] build: update build tools --- .nuke/parameters.json | 2 +- build.ps1 | 17 +++++++++++------ build.sh | 13 +++++++++---- build/Build.cs | 4 ++-- build/_build.csproj | 5 ++--- build/_build.csproj.DotSettings | 1 + 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.nuke/parameters.json b/.nuke/parameters.json index bd44d19..55c0667 100644 --- a/.nuke/parameters.json +++ b/.nuke/parameters.json @@ -1,4 +1,4 @@ { "$schema": "./build.schema.json", "Solution": "Intility.Logging.sln" -} \ No newline at end of file +} diff --git a/build.ps1 b/build.ps1 index bbaa118..4634dc0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -18,11 +18,10 @@ $TempDirectory = "$PSScriptRoot\\.nuke\temp" $DotNetGlobalFile = "$PSScriptRoot\\global.json" $DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" -$DotNetChannel = "Current" +$DotNetChannel = "STS" -$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 -$env:DOTNET_MULTILEVEL_LOOKUP = 0 +$env:DOTNET_NOLOGO = 1 ########################################################################### # EXECUTION @@ -56,14 +55,20 @@ else { # Install by channel or version $DotNetDirectory = "$TempDirectory\dotnet-win" if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } } else { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } } $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" + $env:PATH = "$DotNetDirectory;$env:PATH" } -Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" +Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" + +if (Test-Path env:NUKE_ENTERPRISE_TOKEN) { + & $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null + & $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null +} ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh index e8961f9..fdff0c6 100755 --- a/build.sh +++ b/build.sh @@ -14,11 +14,10 @@ TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" -DOTNET_CHANNEL="Current" +DOTNET_CHANNEL="STS" export DOTNET_CLI_TELEMETRY_OPTOUT=1 -export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 -export DOTNET_MULTILEVEL_LOOKUP=0 +export DOTNET_NOLOGO=1 ########################################################################### # EXECUTION @@ -54,9 +53,15 @@ else "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path fi export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" + export PATH="$DOTNET_DIRECTORY:$PATH" fi -echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)" +echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" + +if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then + "$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true + "$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true +fi "$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/Build.cs b/build/Build.cs index a6be38c..a428b53 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -24,7 +24,7 @@ class Build : NukeBuild /// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VSCode https://nuke.build/vscode - public static int Main () => Execute(x => x.Compile); + public static int Main() => Execute(x => x.Compile); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; @@ -90,7 +90,7 @@ class Build : NukeBuild .DependsOn(Pack) .Requires(() => NugetApiKey) .Requires(() => PackageSource) - .Executes(() => + .Executes(() => { DotNetNuGetPush(s => s .SetTargetPath(OutputDirectory / $"*.nupkg") diff --git a/build/_build.csproj b/build/_build.csproj index 893db0e..7399724 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -4,18 +4,17 @@ Exe net9.0 - CS0649;CS0169 + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 .. .. 1 + false - - diff --git a/build/_build.csproj.DotSettings b/build/_build.csproj.DotSettings index c8947fc..a778f33 100644 --- a/build/_build.csproj.DotSettings +++ b/build/_build.csproj.DotSettings @@ -3,6 +3,7 @@ DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW + DO_NOT_SHOW Implicit Implicit ExpressionBody From 642840beb6531d55af1d1558fc00689e3f4de12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Mon, 25 Nov 2024 09:54:40 +0100 Subject: [PATCH 3/7] ci: update to .net 9 --- .github/workflows/compile.yaml | 4 ++-- .github/workflows/publish.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 9fdddd1..930e69c 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -17,10 +17,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup .NET 8 + - name: Setup .NET 9 uses: actions/setup-dotnet@v4 with: - dotnet-version: '8.0.x' + dotnet-version: '9.0.x' - name: Build with Nuke run: ./build.sh compile shell: bash \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c2b2e32..9cbc442 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,10 +15,10 @@ jobs: with: fetch-depth: 0 - - name: Setup .NET 8 + - name: Setup .NET 9 uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.* + dotnet-version: 9.0.* - name: Publish to NuGet with Nuke run: ./build.sh push --nuget-api-key ${{ secrets.NUGET_API_KEY }} From c75775a635783f218303b3a0c827f1742928d520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Mon, 25 Nov 2024 12:01:00 +0100 Subject: [PATCH 4/7] fix: update all packages and change Serilog.Sinks.Elasticsearch to Elastic.Serilog.Sinks. Remove Dynatrace. --- Intility.Logging.sln | 15 ------ .../MinimalApiSample/MinimalApiSample.csproj | 3 +- samples/MinimalApiSample/Program.cs | 3 +- samples/MinimalApiSample/appsettings.json | 6 +-- samples/WebSample/Program.cs | 3 +- samples/WebSample/WebSample.csproj | 1 - samples/WebSample/appsettings.json | 6 +-- samples/WorkerSample/WorkerSample.csproj | 2 +- ...tility.Extensions.Logging.Dynatrace.csproj | 33 ------------ .../LoggerBuilderExtensions.cs | 36 ------------- ...ty.Extensions.Logging.Elasticsearch.csproj | 10 ++-- .../LoggerBuilderExtensions.cs | 52 ++++++++++++------- .../Intility.Extensions.Logging.Sentry.csproj | 6 +-- .../Intility.Extensions.Logging.csproj | 19 +------ .../Intility.Logging.AspNetCore.csproj | 30 ++--------- 15 files changed, 52 insertions(+), 173 deletions(-) delete mode 100644 src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj delete mode 100644 src/Intility.Extensions.Logging.Dynatrace/LoggerBuilderExtensions.cs diff --git a/Intility.Logging.sln b/Intility.Logging.sln index 22fe1ed..f2265aa 100644 --- a/Intility.Logging.sln +++ b/Intility.Logging.sln @@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkerSample", "samples\Wor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalApiSample", "samples\MinimalApiSample\MinimalApiSample.csproj", "{B647AC70-7210-462A-A43C-6EB4AFCB7ED4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intility.Extensions.Logging.Dynatrace", "src\Intility.Extensions.Logging.Dynatrace\Intility.Extensions.Logging.Dynatrace.csproj", "{B94B9317-E255-4851-9110-0366906EA8A8}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{FEC7C612-B49E-41BD-B29A-9EFC84E92F42}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{B27B120C-6614-4A6D-816F-F8B22DBFE789}" @@ -124,18 +122,6 @@ Global {B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x64.Build.0 = Release|Any CPU {B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x86.ActiveCfg = Release|Any CPU {B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x86.Build.0 = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|x64.ActiveCfg = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|x64.Build.0 = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|x86.ActiveCfg = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Debug|x86.Build.0 = Debug|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|Any CPU.Build.0 = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|x64.ActiveCfg = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|x64.Build.0 = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|x86.ActiveCfg = Release|Any CPU - {B94B9317-E255-4851-9110-0366906EA8A8}.Release|x86.Build.0 = Release|Any CPU {B27B120C-6614-4A6D-816F-F8B22DBFE789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B27B120C-6614-4A6D-816F-F8B22DBFE789}.Debug|x64.ActiveCfg = Debug|Any CPU {B27B120C-6614-4A6D-816F-F8B22DBFE789}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -154,7 +140,6 @@ Global {2C7C52E9-835F-4051-9A5E-7D985545A795} = {A5767C5D-9A48-4485-8D5E-686F34B2B766} {25312E6A-4BA3-4FDF-AA7C-CF2A10CDA2AA} = {A5767C5D-9A48-4485-8D5E-686F34B2B766} {B647AC70-7210-462A-A43C-6EB4AFCB7ED4} = {A5767C5D-9A48-4485-8D5E-686F34B2B766} - {B94B9317-E255-4851-9110-0366906EA8A8} = {4073E5F4-CD63-4DAA-864D-83A76827807E} {B27B120C-6614-4A6D-816F-F8B22DBFE789} = {FEC7C612-B49E-41BD-B29A-9EFC84E92F42} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/samples/MinimalApiSample/MinimalApiSample.csproj b/samples/MinimalApiSample/MinimalApiSample.csproj index f2bef9e..7f4410a 100644 --- a/samples/MinimalApiSample/MinimalApiSample.csproj +++ b/samples/MinimalApiSample/MinimalApiSample.csproj @@ -7,8 +7,7 @@ - - + diff --git a/samples/MinimalApiSample/Program.cs b/samples/MinimalApiSample/Program.cs index c286d59..ea8c049 100644 --- a/samples/MinimalApiSample/Program.cs +++ b/samples/MinimalApiSample/Program.cs @@ -6,8 +6,7 @@ { logging.UseDefaultEnrichers() .UseElasticsearch() - .UseSentry() - .UseDynatrace(); + .UseSentry(); }); // Add services to the container. diff --git a/samples/MinimalApiSample/appsettings.json b/samples/MinimalApiSample/appsettings.json index 915297e..cef24ed 100644 --- a/samples/MinimalApiSample/appsettings.json +++ b/samples/MinimalApiSample/appsettings.json @@ -8,11 +8,7 @@ "AllowedHosts": "*", "Elasticsearch": { "Endpoints": "localhost:9200", - "IndexFormat": "my-service-{0:yyyy.MM}" - }, - "Dynatrace": { - "IngestUrl": "localhost:9200", - "AccessToken": "test" + "IndexFormat": "my-service" }, "Sentry": { "Dsn": "https://examplePublicKey@o0.ingest.sentry.io/0", diff --git a/samples/WebSample/Program.cs b/samples/WebSample/Program.cs index fa3cc22..20fcc07 100644 --- a/samples/WebSample/Program.cs +++ b/samples/WebSample/Program.cs @@ -17,8 +17,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { logging.UseDefaultEnrichers() .UseElasticsearch() - .UseSentry() - .UseDynatrace(); + .UseSentry(); }) .ConfigureWebHostDefaults(webBuilder => { diff --git a/samples/WebSample/WebSample.csproj b/samples/WebSample/WebSample.csproj index 0bd9a48..2f2d96e 100644 --- a/samples/WebSample/WebSample.csproj +++ b/samples/WebSample/WebSample.csproj @@ -5,7 +5,6 @@ - diff --git a/samples/WebSample/appsettings.json b/samples/WebSample/appsettings.json index 86e3482..51e1b6b 100644 --- a/samples/WebSample/appsettings.json +++ b/samples/WebSample/appsettings.json @@ -14,11 +14,7 @@ }, "Elasticsearch": { "Endpoints": "localhost:9200", - "IndexFormat": "my-service-{0:yyyy.MM}" - }, - "Dynatrace": { - "IngestUrl": "localhost:9200", - "AccessToken": "test" + "IndexFormat": "my-service" }, "Sentry": { "Dsn": "https://examplePublicKey@o0.ingest.sentry.io/0", diff --git a/samples/WorkerSample/WorkerSample.csproj b/samples/WorkerSample/WorkerSample.csproj index 5650303..4f2eb64 100644 --- a/samples/WorkerSample/WorkerSample.csproj +++ b/samples/WorkerSample/WorkerSample.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj b/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj deleted file mode 100644 index 05d86ac..0000000 --- a/src/Intility.Extensions.Logging.Dynatrace/Intility.Extensions.Logging.Dynatrace.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - net6.0;net7.0;net8.0;net9.0 - - - - true - Intility.Extensions.Logging.Dynatrace - intility;logging;extensions;dynatrace - - Enable Dynatrace logging provider. - - Intility - Intility - Herman Jensen, Emil Kjelsrud, Thorstein Løkensgard - https://github.com/Intility/Intility.Logging - intility-logo.png - - - - - - - - - - - - - - - diff --git a/src/Intility.Extensions.Logging.Dynatrace/LoggerBuilderExtensions.cs b/src/Intility.Extensions.Logging.Dynatrace/LoggerBuilderExtensions.cs deleted file mode 100644 index 5161c47..0000000 --- a/src/Intility.Extensions.Logging.Dynatrace/LoggerBuilderExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Serilog; -using System; - -namespace Intility.Extensions.Logging -{ - public static class LoggerBuilderExtensions - { - /// - /// Uses Dynatrace sink if IngestUrl is defined in the . - /// - /// - /// - /// - public static ILoggerBuilder UseDynatrace(this ILoggerBuilder builder, string configSection = "Dynatrace") - { - var configuration = builder.Host.Configuration.GetSection(configSection); - var ingestUrl = configuration["IngestUrl"]; - if (string.IsNullOrWhiteSpace(ingestUrl)) - { - return builder; - } - - var accessToken = configuration["AccessToken"]; - if (string.IsNullOrWhiteSpace(accessToken)) - { - throw new Exception("Failed to initialize Dynatrace sink", new ArgumentException("missing dynatrace config: " + configSection + ":AccessToken")); - } - - var hostName = configuration["HostName"] ?? null; - var applicationId = configuration["ApplicationId"] ?? null; - - builder.Configuration.WriteTo.Dynatrace(accessToken, ingestUrl, applicationId: applicationId, hostName: hostName); - return builder; - } - } -} diff --git a/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj b/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj index db8eef2..2d7fb9e 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj +++ b/src/Intility.Extensions.Logging.Elasticsearch/Intility.Extensions.Logging.Elasticsearch.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net9.0;net8.0 @@ -18,10 +18,6 @@ intility-logo.png - - - - @@ -30,4 +26,8 @@ + + + + diff --git a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs index 022418f..b1a8d24 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs +++ b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs @@ -1,5 +1,9 @@ -using Serilog; -using Serilog.Sinks.Elasticsearch; +using Elastic.CommonSchema.Serilog; +using Elastic.Ingest.Elasticsearch; +using Elastic.Ingest.Elasticsearch.DataStreams; +using Elastic.Serilog.Sinks; +using Elastic.Transport; +using Serilog.Debugging; using System; using System.Linq; @@ -40,40 +44,48 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin var username = elasticConfig["Username"]; var password = elasticConfig["Password"]; + var llmPolicy = elasticConfig["LLMPolicy"]; var indexFormat = elasticConfig["IndexFormat"]; var versionString = elasticConfig["Version"]; if (string.IsNullOrWhiteSpace(indexFormat)) { - throw new Exception("Failed to initialize Elasticsearch sink", + throw new Exception("Failed to initialize Elasticsearch sink", new ArgumentException($"missing elastic config: {configSection}:IndexFormat")); } var endpoints = elasticEndpoints.Split(',') .Select(endpoint => new Uri(endpoint)); - var versionFormat = string.IsNullOrWhiteSpace(versionString) - ? AutoRegisterTemplateVersion.ESv7 - : Enum.Parse(versionString); - var options = new ElasticsearchSinkOptions(endpoints) + foreach (var endpoint in endpoints) { - TypeName = "logevent", - IndexFormat = indexFormat, - NumberOfShards = 1, - NumberOfReplicas = 1, - AutoRegisterTemplate = true, - AutoRegisterTemplateVersion = versionFormat - }; + var settings = new TransportConfiguration(endpoint) + .Authentication(new BasicAuthentication(username, password)); - if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) - { - options.ModifyConnectionSettings = c => c.BasicAuthentication(username, password); - } + var transport = new DistributedTransport(settings); + var sinkOptions = new ElasticsearchSinkOptions(transport) + { + DataStream = new DataStreamName(indexFormat), + BootstrapMethod = BootstrapMethod.Failure, + ChannelDiagnosticsCallback = channel => { + SelfLog.WriteLine( + $"Failure={channel.PublishSuccess}, " + + $"Message={channel}, " + + $"Exception={channel.ObservedException}" + ); + }, + TextFormatting = new EcsTextFormatterConfiguration() + }; - configure?.Invoke(options); + if(!string.IsNullOrWhiteSpace(llmPolicy)) + { + sinkOptions.IlmPolicy = llmPolicy; + } + + builder.Configuration.WriteTo.Elasticsearch(sinkOptions); + } - builder.Configuration.WriteTo.Elasticsearch(options); return builder; } } diff --git a/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj b/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj index 29ae2d9..a3b832b 100644 --- a/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj +++ b/src/Intility.Extensions.Logging.Sentry/Intility.Extensions.Logging.Sentry.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net9.0;net8.0 @@ -19,8 +19,8 @@ - - + + diff --git a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj index 2fabd07..a0434a2 100644 --- a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj +++ b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0;net8.0;net9.0 + net9.0;net8.0 @@ -21,23 +21,8 @@ - - - - - - - - - - - - - - - - + diff --git a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj index 5e697f0..0ca9c21 100644 --- a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj +++ b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net9.0;net8.0 @@ -21,36 +21,14 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - + From ecc48dcf87e8429381f5b29d1d68728cffcb5943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Tue, 26 Nov 2024 09:43:55 +0100 Subject: [PATCH 5/7] fix: add .net support --- build/Build.cs | 2 +- .../LoggerBuilderExtensions.cs | 1 - .../Intility.Extensions.Logging.csproj | 9 ++++++++- .../Intility.Logging.AspNetCore.csproj | 11 ++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/build/Build.cs b/build/Build.cs index a428b53..0a1e380 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -37,7 +37,7 @@ class Build : NukeBuild [Solution] readonly Solution Solution; [GitRepository] readonly GitRepository GitRepository; - [GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion GitVersion; + [GitVersion(NoFetch = true, Framework = "net9.0")] readonly GitVersion GitVersion; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath TestsDirectory => RootDirectory / "tests"; diff --git a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs index b1a8d24..3abd4c2 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs +++ b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs @@ -46,7 +46,6 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin var password = elasticConfig["Password"]; var llmPolicy = elasticConfig["LLMPolicy"]; var indexFormat = elasticConfig["IndexFormat"]; - var versionString = elasticConfig["Version"]; if (string.IsNullOrWhiteSpace(indexFormat)) { diff --git a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj index a0434a2..c4197b3 100644 --- a/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj +++ b/src/Intility.Extensions.Logging/Intility.Extensions.Logging.csproj @@ -21,9 +21,16 @@ - + + + + + + + + diff --git a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj index 0ca9c21..b39ab4c 100644 --- a/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj +++ b/src/Intility.Logging.AspNetCore/Intility.Logging.AspNetCore.csproj @@ -26,9 +26,18 @@ + + + + + + + + - + + From 0c4f2f4b4bb26e8df6b30f5f45738c66efafd439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Tue, 26 Nov 2024 10:29:12 +0100 Subject: [PATCH 6/7] fix: allow custom dataSet and namespace name --- .../LoggerBuilderExtensions.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs index 3abd4c2..c2e6813 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs +++ b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs @@ -47,16 +47,28 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin var llmPolicy = elasticConfig["LLMPolicy"]; var indexFormat = elasticConfig["IndexFormat"]; + var dataSet = elasticConfig["DataSet"]; + var namespaceName = elasticConfig["Namespace"]; + if (string.IsNullOrWhiteSpace(indexFormat)) { throw new Exception("Failed to initialize Elasticsearch sink", new ArgumentException($"missing elastic config: {configSection}:IndexFormat")); } + if (string.IsNullOrWhiteSpace(dataSet)) + { + dataSet = "generic"; + } + + if (string.IsNullOrWhiteSpace(namespaceName)) + { + namespaceName = "default"; + } + var endpoints = elasticEndpoints.Split(',') .Select(endpoint => new Uri(endpoint)); - foreach (var endpoint in endpoints) { var settings = new TransportConfiguration(endpoint) From c1d7a2d27cde595c529a1cb555d1f436510f65b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorstein=20L=C3=B8kensgard?= Date: Tue, 26 Nov 2024 11:53:19 +0100 Subject: [PATCH 7/7] fix: use null-coalescing for dataset and namespace --- .../LoggerBuilderExtensions.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs index c2e6813..4b1c1a7 100644 --- a/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs +++ b/src/Intility.Extensions.Logging.Elasticsearch/LoggerBuilderExtensions.cs @@ -47,8 +47,8 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin var llmPolicy = elasticConfig["LLMPolicy"]; var indexFormat = elasticConfig["IndexFormat"]; - var dataSet = elasticConfig["DataSet"]; - var namespaceName = elasticConfig["Namespace"]; + var dataSet = string.IsNullOrWhiteSpace(elasticConfig["DataSet"]) ? "generic" : elasticConfig["DataSet"]; + var namespaceName = string.IsNullOrWhiteSpace(elasticConfig["Namespace"]) ? "default" : elasticConfig["Namespace"]; if (string.IsNullOrWhiteSpace(indexFormat)) { @@ -56,16 +56,6 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin new ArgumentException($"missing elastic config: {configSection}:IndexFormat")); } - if (string.IsNullOrWhiteSpace(dataSet)) - { - dataSet = "generic"; - } - - if (string.IsNullOrWhiteSpace(namespaceName)) - { - namespaceName = "default"; - } - var endpoints = elasticEndpoints.Split(',') .Select(endpoint => new Uri(endpoint)); @@ -77,7 +67,7 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin var transport = new DistributedTransport(settings); var sinkOptions = new ElasticsearchSinkOptions(transport) { - DataStream = new DataStreamName(indexFormat), + DataStream = new DataStreamName(indexFormat, dataSet, namespaceName), BootstrapMethod = BootstrapMethod.Failure, ChannelDiagnosticsCallback = channel => { SelfLog.WriteLine(