serilog / serilog-sinks-file

Write Serilog events to files in text and JSON formats, optionally rolling on time or size
Apache License 2.0
333 stars 117 forks source link

File Sink Not Working with broadFileSystemAccess Capability in UWP Apps #281

Closed vectoralexey closed 11 months ago

vectoralexey commented 1 year ago

Issue Description

We encountered a problem when trying to use Serilog's built-in File sink in a UWP app with the broadFileSystemAccess capability enabled. Even though the capability allows the app to access the file system more broadly, the File sink still fails to write logs to custom folders.

Steps to Reproduce

Create a UWP app with the broadFileSystemAccess capability enabled in the app manifest. Configure Serilog to use the built-in File sink, targeting a custom folder outside the app's local storage. Run the app and attempt to write logs using Serilog.

Expected Behavior

Serilog's File sink should be able to write logs to the custom folder specified in the configuration, considering that the broadFileSystemAccess capability is enabled.

Actual Behavior

The File sink fails to write logs to the custom folder, raising an UnauthorizedAccessException or other file access-related exceptions.

Additional Information

The primary issue seems to be that Serilog's File sink uses standard .NET file I/O APIs, which are not designed to work with the restricted file system access model in UWP apps. A custom sink that utilizes the Windows Storage APIs could be a potential solution, but it introduces several challenges related to synchronization, rolling, retention, and performance optimization.

We are looking for guidance on how to resolve this issue or suggestions for alternative approaches to logging in UWP apps that can work with custom folders and the broadFileSystemAccess capability.

nblumhardt commented 1 year ago

Hi Oleksii! Thanks for the note.

I think any deeper UWP support would be best developed in a fork or custom sink right now - I don't believe any of the Serilog maintainers are working day-to-day with UWP or have any special knowledge in this area (please correct me if I'm wrong, folks out there :-)).

If you're interested in creating a custom sink, based off of the Serilog.Sinks.File codebase, and would like an extra set of eyes on the code or PRs, please feel free to @ me personally from your repository and I'll aim to follow along.

bartelink commented 11 months ago

Closing on a basis similar to https://github.com/serilog/serilog-sinks-file/issues/270#issuecomment-1770440948 It's better for this repo not to have issues pertaining to the huge diversity of environments out there as a) the authors may or may not have access/awareness of such environments b) there are better avenues for troubleshooting advice given the fact that the Sink uses the standard .NET System.IO. APIs