Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting stderr stream to a file in MonoTouch

Is it somehow possible to redirect the stderr to a file under MonoTouch?

In Objective-C you can do that with

freopen("file.log", "a+", stderr);

as described here and here.

But how can I do the same thing under MonoTouch?

The Xamarin Docs provide a section Working with the File System but I don't know hot to access the stderr stream from there.

Thanks in advance.

like image 446
saxos Avatar asked Dec 01 '25 09:12

saxos


1 Answers

You do it the .NET way using Console.SetError.

OTOH it's often easier to do all your writing directly into your own TextWriter instance.

That will allow you to change the destination of the error output easily between the normal Console.Error, a file or anything else (e.g. Touch.Unit uses a writer that connect to a remove server socket).

like image 141
poupou Avatar answered Dec 04 '25 00:12

poupou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!