MatrixRoomUtils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

LogView.razor (1387B)


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