about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/LogView.razor
blob: d541b826990c96062f7a863e2716e6cf7f399ece (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@* @using System.Text *@
@* @if (LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) { *@
@*     <u>Logs</u> *@
@*     <br/> *@
@*     <pre> *@
@*         @_stringBuilder *@
@*     </pre> *@
@* } *@
@* *@
@* @code { *@
@*     StringBuilder _stringBuilder = new(); *@
@* *@
@*     protected override async Task OnInitializedAsync() { *@
@*         if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging) { *@
@*             Console.WriteLine("Console logging disabled!"); *@
@*             var _sw = new StringWriter(); *@
@*             Console.SetOut(_sw); *@
@*             Console.SetError(_sw); *@
@*             return; *@
@*         } *@
@*         if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) return; *@
@*     //intecept stdout with textwriter to get logs *@
@*         var sw = new StringWriter(_stringBuilder); *@
@*         Console.SetOut(sw); *@
@*         Console.SetError(sw); *@
@*     //keep updated *@
@*         var length = 0; *@
@*         Task.Run(async () => { *@
@*             while (true) { *@
@*                 await Task.Delay(100); *@
@*                 if (_stringBuilder.Length != length) { *@
@*                     StateHasChanged(); *@
@*                     length = _stringBuilder.Length; *@
@*                 } *@
@*             } *@
@*     // ReSharper disable once FunctionNeverReturns - This is intentional behavior *@
@*         }); *@
@*         await base.OnInitializedAsync(); *@
@*     } *@
@* *@
@* } *@