-
Notifications
You must be signed in to change notification settings - Fork 125
Fix issue with force-reopen after 30 minutes #337
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
4 commits
Select commit
Hold shift + click to select a range
7c44444
Fix issue with force-reopen after 30 minutes
Falco20019 a3cd930
Fix issue with FileSink not closing the stream on hook errors
Falco20019 836854e
Ensure SelfLog will not tear into other tests
Falco20019 455a10f
Comment out SelfLog for now as requested
Falco20019 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Text; | ||
Falco20019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Falco20019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace Serilog.Sinks.File.Tests.Support; | ||
This comment was marked as spam.
Sorry, something went wrong. 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. This makes no sense. Reported the user as spam bot to avoid further interaction. |
||
|
||
Falco20019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// <inheritdoc /> | ||
/// <summary> | ||
/// Demonstrates the use of <seealso cref="T:Serilog.FileLifecycleHooks" />, by failing to open for the given amount of times. | ||
/// </summary> | ||
class FailOpeningHook : FileLifecycleHooks | ||
{ | ||
readonly bool _asFileLocked; | ||
readonly int[] _failingInstances; | ||
|
||
public int TimesOpened { get; private set; } | ||
|
||
public FailOpeningHook(bool asFileLocked, params int[] failingInstances) | ||
{ | ||
_asFileLocked = asFileLocked; | ||
_failingInstances = failingInstances; | ||
} | ||
|
||
public override Stream OnFileOpened(string path, Stream stream, Encoding encoding) | ||
{ | ||
TimesOpened++; | ||
if (_failingInstances.Contains(TimesOpened)) | ||
{ | ||
var message = $"We failed on try {TimesOpened}, the file was locked: {_asFileLocked}"; | ||
|
||
throw _asFileLocked | ||
? new IOException(message) | ||
: new Exception(message); | ||
} | ||
|
||
return base.OnFileOpened(path, stream, encoding); | ||
} | ||
} |
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.
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.
Not sure about doing this under the lock, since
SelfLog
may be writing somewhere slow. Might be safer to drop this for now, and reconsider separately.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.
I can do that, I just had issues already that stuff was lost and we never found out why. But will remove it to progress with the PR for now. This should really never happen on regular use-cases and therefore should be neglectable and if the file was locked, we also use the
SelfLog
, so it was the nearest thing to consider :)I will just comment it out so that it's easy to add in the future.