77using ShowMeTheXAML ;
88using System ;
99using System . Linq ;
10+ using System . Net . Sockets ;
11+ using System . Net ;
1012using System . Reflection ;
13+ using System . Text ;
1114using Uno . Extensions ;
1215using Uno . Gallery . Entities ;
1316using Uno . Gallery . Helpers ;
2225
2326namespace Uno . Gallery
2427{
28+ public class ConsoleForwarder
29+ {
30+ public static void Enable ( string ip , int port = 1234 )
31+ {
32+ var client = new TcpClient { NoDelay = true } ;
33+ client . Connect ( IPAddress . Parse ( ip ) , port ) ;
34+
35+ var writer = new StreamWriter ( client . GetStream ( ) , Encoding . UTF8 ) { AutoFlush = true } ;
36+ Console . SetOut ( writer ) ;
37+ Console . SetError ( writer ) ;
38+
39+ Console . WriteLine ( $ "Console forwarding to { ip } :{ port } is active!") ;
40+
41+ var stayAlive = new Timer ( _ =>
42+ {
43+ Console . WriteLine ( $ "[[[ ALIVE ]]] { DateTime . Now : F} [[[ ALIVE ]]] .") ;
44+ writer . Flush ( ) ;
45+ } ) ;
46+ stayAlive . Change ( 30_000 , 30_000 ) ;
47+ }
48+ }
49+
50+ public class ConsoleWriter
51+ {
52+ public static void Enable ( string ? path = null )
53+ {
54+ path ??= $ "C:\\ tmp\\ log-{ DateTime . Now : yy-MM-dd HH-mm-ss} .txt";
55+ var file = File . Open ( path , FileMode . CreateNew , FileAccess . Write , FileShare . ReadWrite ) ;
56+
57+ var writer = new StreamWriter ( file , Encoding . UTF8 ) { AutoFlush = true } ;
58+ Console . SetOut ( writer ) ;
59+ Console . SetError ( writer ) ;
60+
61+ Console . WriteLine ( $ "Console writing to { path } is active!") ;
62+
63+ var stayAlive = new Timer ( _ =>
64+ {
65+ Console . WriteLine ( $ "[[[ ALIVE ]]] { DateTime . Now : F} [[[ ALIVE ]]] .") ;
66+ writer . Flush ( ) ;
67+ } ) ;
68+ stayAlive . Change ( 30_000 , 30_000 ) ;
69+ }
70+ }
71+
72+
73+
2574 /// <summary>
2675 /// Provides application-specific behavior to supplement the default Application class.
2776 /// </summary>
@@ -39,6 +88,9 @@ public partial class App : Application
3988 /// </summary>
4089 public App ( )
4190 {
91+ //ConsoleForwarder.Enable("172.20.100.242");
92+ ConsoleWriter . Enable ( ) ;
93+
4294 Instance = this ;
4395
4496 ConfigureFeatureFlags ( ) ;
0 commit comments