Skip to content

Add ability to capture path of log file opened, via FileLifecycleHooks #189

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

Conversation

augustoproiete
Copy link
Member

@augustoproiete augustoproiete commented Nov 9, 2020

Adds an overload to FileLifecycleHooks that includes the path to the log file that has been opened.

public virtual Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding) { ... }

By default, it calls the current OnFileOpened(Stream, Encoding) to maintain compatibility with existing hooks.

We can consider marking the current OnFileOpened(Stream, Encoding) as Obsolete on this or on a future pull-request depending on the next milestone/release.


Resolves #191

@nblumhardt
Copy link
Member

Looks good to me; which scenario are we aiming to hit with this, in particular?

@augustoproiete
Copy link
Member Author

@nblumhardt @cocowalla I just did what I should have done from the start and opened an issue to discuss and add more context.

@augustoproiete augustoproiete force-pushed the capture-log-file-path-in-hooks branch from 1e7331b to f32a809 Compare November 9, 2020 16:52
@augustoproiete augustoproiete force-pushed the capture-log-file-path-in-hooks branch from f32a809 to 4c8c3d4 Compare November 10, 2020 04:45
@nblumhardt nblumhardt merged commit 7cf84eb into serilog:dev Nov 10, 2020
@nblumhardt
Copy link
Member

:shipit:

@augustoproiete augustoproiete deleted the capture-log-file-path-in-hooks branch November 10, 2020 22:38
@Falco20019
Copy link
Contributor

Falco20019 commented Jan 18, 2021

Is there a roadmap on when this gets released? We are waiting for this. Our use case is having encryption applied on the file. When appending, we need to read the initialization vector from the header. Since neither the underlying stream nor the file name is offered through WriteCountingStream, we have no way in appending existing files right now.

Another problem that we have, is that the underlying stream is opened with FileShare.Read. If you want to append an encrypted stream, you need to decrypt the last block to remove the padding before writing the next data. So this is currently not possible.

@nblumhardt
Copy link
Member

Hi @Falco20019 - have you tried the -dev package, and does it work for you? Feedback would be great, thanks 👍

@Falco20019
Copy link
Contributor

@nblumhardt Yes, I tried it with that and that‘s when I saw the problems I documented in #199. So sadly this was only part of the solution since the underlying stream is not allowing write permission as it already opened the file with FileShare.Read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to get the file path of the log file via hooks
3 participants