Skip to content
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

Unable to create File on Xamarin.iOS #161

Closed
prin53 opened this issue Jul 4, 2020 · 3 comments
Closed

Unable to create File on Xamarin.iOS #161

prin53 opened this issue Jul 4, 2020 · 3 comments

Comments

@prin53
Copy link

prin53 commented Jul 4, 2020

I have this error when running FileSink on iOS device (simulator works fine):

Caught exception while emitting to sink Serilog.Sinks.File.RollingFileSink: System.UnauthorizedAccessException: Access to the path '/private/var/containers/Bundle/Application/ADEC88A7-24D1-4BB1-B680-55CAC821ECA7/App.iOS.app/file:/var/mobile/Containers/Data/Application/831F4448-5AA3-45F7-92A7-DEF85132C3BC/Documents/Logs' is denied. ---> System.IO.IOException: Operation not permitted
--- End of inner exception stack trace ---
at System.IO.FileSystem.CreateDirectory (System.String fullPath) [0x00192] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs:319
at System.IO.Directory.CreateDirectory (System.String path) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:40
at Serilog.Sinks.File.FileSink..ctor (System.String path, Serilog.Formatting.ITextFormatter textFormatter, System.Nullable1[T] fileSizeLimitBytes, System.Text.Encoding encoding, System.Boolean buffered, Serilog.Sinks.File.FileLifecycleHooks hooks) [0x00088] in C:\projects\serilog-sinks-file\src\Serilog.Sinks.File\Sinks\File\FileSink.cs:72 at Serilog.Sinks.File.RollingFileSink.OpenFile (System.DateTime now, System.Nullable1[T] minSequence) [0x00133] in C:\projects\serilog-sinks-file\src\Serilog.Sinks.File\Sinks\File\RollingFileSink.cs:149
at Serilog.Sinks.File.RollingFileSink.AlignCurrentFileTo (System.DateTime now, System.Boolean nextSequence) [0x0000d] in C:\projects\serilog-sinks-file\src\Serilog.Sinks.File\Sinks\File\RollingFileSink.cs:92
at Serilog.Sinks.File.RollingFileSink.Emit (Serilog.Events.LogEvent logEvent) [0x00038] in C:\projects\serilog-sinks-file\src\Serilog.Sinks.File\Sinks\File\RollingFileSink.cs:79
at Serilog.Core.Sinks.SafeAggregateSink.Emit (Serilog.Events.LogEvent logEvent) [0x0000f] in :0

This happens because of Path.GetFullPath method call in the PathRoller.

Expected and valid path: file:/var/mobile/Containers/Data/Application/831F4448-5AA3-45F7-92A7-DEF85132C3BC/Documents/Logs
Actual path: /private/var/containers/Bundle/Application/ADEC88A7-24D1-4BB1-B680-55CAC821ECA7/App.iOS.app/file:/var/mobile/Containers/Data/Application/831F4448-5AA3-45F7-92A7-DEF85132C3BC/Documents/Logs

@nblumhardt
Copy link
Member

No idea how to tackle this, sorry - open to ideas, but seems like a Xamarin bug, perhaps?

@prin53
Copy link
Author

prin53 commented Aug 9, 2020

Is it possible to let users provide the full path themselves? This should fix the problem and also allow the provided path to be used to get logs without hidden manipulation. What do you think?

@prin53
Copy link
Author

prin53 commented Nov 1, 2020

Looks like it works now.

@prin53 prin53 closed this as completed Nov 1, 2020
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

No branches or pull requests

2 participants