-
Notifications
You must be signed in to change notification settings - Fork 125
Support ILoggingFailureListener
#342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# If this file is renamed, the incrementing run attempt number will be reset. | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ "dev", "main" ] | ||
pull_request: | ||
branches: [ "dev", "main" ] | ||
|
||
env: | ||
CI_BUILD_NUMBER_BASE: ${{ github.run_number }} | ||
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }} | ||
|
||
jobs: | ||
build: | ||
|
||
# The build must run on Windows so that .NET Framework targets can be built and tested. | ||
runs-on: windows-latest | ||
|
||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 9.0.x | ||
- name: Compute build number | ||
shell: bash | ||
run: | | ||
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV | ||
- name: Build and Publish | ||
env: | ||
DOTNET_CLI_TELEMETRY_OPTOUT: true | ||
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
shell: pwsh | ||
run: | | ||
./Build.ps1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,79 @@ | ||
Write-Output "build: Tool versions follow" | ||
|
||
dotnet --version | ||
dotnet --list-sdks | ||
|
||
Write-Output "build: Build started" | ||
|
||
Push-Location $PSScriptRoot | ||
try { | ||
if(Test-Path .\artifacts) { | ||
Write-Output "build: Cleaning ./artifacts" | ||
Remove-Item ./artifacts -Force -Recurse | ||
} | ||
|
||
if(Test-Path .\artifacts) { | ||
Write-Output "build: Cleaning ./artifacts" | ||
Remove-Item ./artifacts -Force -Recurse | ||
} | ||
& dotnet restore --no-cache | ||
|
||
& dotnet restore --no-cache | ||
$dbp = [Xml] (Get-Content .\Directory.Version.props) | ||
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix | ||
|
||
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH]; | ||
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER]; | ||
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] | ||
Write-Output "build: Package version prefix is $versionPrefix" | ||
|
||
Write-Output "build: Package version suffix is $suffix" | ||
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH]; | ||
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER]; | ||
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"] | ||
$commitHash = $(git rev-parse --short HEAD) | ||
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] | ||
|
||
foreach ($src in Get-ChildItem src/*) { | ||
Push-Location $src | ||
Write-Output "build: Package version suffix is $suffix" | ||
Write-Output "build: Build version suffix is $buildSuffix" | ||
|
||
Write-Output "build: Packaging project in $src" | ||
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true | ||
if($LASTEXITCODE -ne 0) { throw "Build failed" } | ||
|
||
if ($suffix) { | ||
& dotnet pack -c Release --include-source -o ../../artifacts --version-suffix=$suffix | ||
} else { | ||
& dotnet pack -c Release --include-source -o ../../artifacts | ||
foreach ($src in Get-ChildItem src/*) { | ||
Push-Location $src | ||
|
||
Write-Output "build: Packaging project in $src" | ||
|
||
if ($suffix) { | ||
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix | ||
} else { | ||
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts | ||
} | ||
if($LASTEXITCODE -ne 0) { throw "Packaging failed" } | ||
|
||
Pop-Location | ||
} | ||
if($LASTEXITCODE -ne 0) { throw "Packaging failed" } | ||
|
||
Pop-Location | ||
} | ||
foreach ($test in Get-ChildItem test/*.Tests) { | ||
Push-Location $test | ||
|
||
Write-Output "build: Testing project in $test" | ||
|
||
& dotnet test -c Release --no-build --no-restore | ||
if($LASTEXITCODE -ne 0) { throw "Testing failed" } | ||
|
||
Pop-Location | ||
} | ||
|
||
if ($env:NUGET_API_KEY) { | ||
# GitHub Actions will only supply this to branch builds and not PRs. We publish | ||
# builds from any branch this action targets (i.e. main and dev). | ||
|
||
foreach ($test in Get-ChildItem test/*.Tests) { | ||
Push-Location $test | ||
Write-Output "build: Publishing NuGet packages" | ||
|
||
Write-Output "build: Testing project in $test" | ||
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) { | ||
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" | ||
if($LASTEXITCODE -ne 0) { throw "Publishing failed" } | ||
} | ||
|
||
& dotnet test -c Release | ||
if($LASTEXITCODE -ne 0) { throw "Testing failed" } | ||
if (!($suffix)) { | ||
Write-Output "build: Creating release for version $versionPrefix" | ||
|
||
iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" | ||
} | ||
} | ||
} finally { | ||
Pop-Location | ||
} | ||
|
||
Pop-Location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<VersionPrefix>7.0.0</VersionPrefix> | ||
</PropertyGroup> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "9.0.200", | ||
"allowPrerelease": false, | ||
"rollForward": "latestFeature" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the concept of having every log still appearing somewhere if everything went wrong. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright © Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Serilog.Core; | ||
using Serilog.Debugging; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.File; | ||
|
||
sealed class FailedSink : ILogEventSink, ISetLoggingFailureListener | ||
{ | ||
ILoggingFailureListener _failureListener = SelfLog.FailureListener; | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
_failureListener.OnLoggingFailed(this, LoggingFailureKind.Final, "the sink could not be initialized", [logEvent], exception: null); | ||
} | ||
|
||
public void SetFailureListener(ILoggingFailureListener failureListener) | ||
{ | ||
_failureListener = failureListener ?? throw new ArgumentNullException(nameof(failureListener)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Only a suggestion to comply better with SemVer 2.0.0
https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#pre-release-versions suggests to use the version in the format
7.0.0-selflog-on.1+04ac85d
instead of7.0.0-selflog-on-00001-04ac85d
. Doing this will also allow you to just use$suffix
instead of differentiating with$buildSuffix
since the nuget package (and any relevant other part) will drop the metadata part as documented by https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#normalized-version-numbersUsing the
.
instead of-
before the CI number also signifies it's a numeric and should be sorted as such. NuGet/VisualStudio/... is aware of that, which makes it nicer than padding it to 5 digits. This is widely supported since VS 2017.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would use
7.0.0-ci.1+04ac85d-selflog-on-open-failure
, but tried to keep the suggestion closer to what you do right now.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, there seems to be something in place that adds the full revision anyway:
The result locally was:
7.0.0-selflog-on.1+04ac85d60ddb0e109312ca820a113b599d286dc9
with my change and7.0.0-selflog-on-00001-04ac85d+04ac85d60ddb0e109312ca820a113b599d286dc9
with your current code.I did check if this was local-only or also from the official packages, and the latest version on NuGet is
6.0.0+c7b9bc3d87f9bb98572a52286135efda1e608ad6
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into this! These scripts are from the upstream
serilog/serilog
and we're trying to avoid configuration drift by making any changes up there. I agree this could be better 👍 - I'll leave this as-is here but take a look in the next round of maintenance on the Serilog package.