refactor: replace Console.WriteLine with DiagnosticLog service
All checks were successful
CI / Build (Linux) (push) Successful in 21s

Replace 495+ Console.WriteLine debug statements across handlers, dispatching, services, views, and window components with centralized DiagnosticLog service for proper logging infrastructure. Add new DiagnosticLog.cs service with Debug/Error methods to eliminate debug logging pollution in production code.
This commit is contained in:
2026-03-06 22:06:08 -05:00
parent 08e0c4d2b9
commit e55230c441
70 changed files with 814 additions and 638 deletions

View File

@@ -3,6 +3,7 @@
using SkiaSharp;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Services;
using Microsoft.Maui.Platform.Linux.Window;
using System.Runtime.InteropServices;
@@ -58,7 +59,7 @@ public class GpuRenderingEngine : IDisposable
if (!_gpuAvailable)
{
Console.WriteLine("[GpuRenderingEngine] GPU not available, using software rendering");
DiagnosticLog.Debug("GpuRenderingEngine", "GPU not available, using software rendering");
InitializeSoftwareRendering();
}
@@ -74,25 +75,25 @@ public class GpuRenderingEngine : IDisposable
var glInterface = GRGlInterface.Create();
if (glInterface == null)
{
Console.WriteLine("[GpuRenderingEngine] Failed to create GL interface");
DiagnosticLog.Warn("GpuRenderingEngine", "Failed to create GL interface");
return false;
}
_grContext = GRContext.CreateGl(glInterface);
if (_grContext == null)
{
Console.WriteLine("[GpuRenderingEngine] Failed to create GR context");
DiagnosticLog.Warn("GpuRenderingEngine", "Failed to create GR context");
glInterface.Dispose();
return false;
}
CreateGpuSurface();
Console.WriteLine("[GpuRenderingEngine] GPU acceleration enabled");
DiagnosticLog.Debug("GpuRenderingEngine", "GPU acceleration enabled");
return true;
}
catch (Exception ex)
{
Console.WriteLine($"[GpuRenderingEngine] GPU initialization failed: {ex.Message}");
DiagnosticLog.Error("GpuRenderingEngine", "GPU initialization failed", ex);
return false;
}
}
@@ -124,7 +125,7 @@ public class GpuRenderingEngine : IDisposable
if (_surface == null)
{
Console.WriteLine("[GpuRenderingEngine] Failed to create GPU surface, falling back to software");
DiagnosticLog.Warn("GpuRenderingEngine", "Failed to create GPU surface, falling back to software");
_gpuAvailable = false;
InitializeSoftwareRendering();
return;

View File

@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.Maui.Platform.Linux.Native;
using Microsoft.Maui.Platform.Linux.Services;
using SkiaSharp;
namespace Microsoft.Maui.Platform.Linux.Rendering;
@@ -150,7 +151,7 @@ public sealed class GtkSkiaSurfaceWidget : IDisposable
GtkNative.g_signal_connect_data(_widget, "key-release-event", Marshal.GetFunctionPointerForDelegate(_keyReleaseCallback), IntPtr.Zero, IntPtr.Zero, 0);
GtkNative.g_signal_connect_data(_widget, "scroll-event", Marshal.GetFunctionPointerForDelegate(_scrollCallback), IntPtr.Zero, IntPtr.Zero, 0);
Console.WriteLine($"[GtkSkiaSurfaceWidget] Created with size {width}x{height}");
DiagnosticLog.Debug("GtkSkiaSurfaceWidget", $"Created with size {width}x{height}");
}
private void CreateBuffer(int width, int height)
@@ -179,7 +180,7 @@ public sealed class GtkSkiaSurfaceWidget : IDisposable
_imageInfo.Height,
_imageInfo.RowBytes);
Console.WriteLine($"[GtkSkiaSurfaceWidget] Created buffer {width}x{height}, stride={_imageInfo.RowBytes}");
DiagnosticLog.Debug("GtkSkiaSurfaceWidget", $"Created buffer {width}x{height}, stride={_imageInfo.RowBytes}");
}
public void Resize(int width, int height)
@@ -303,7 +304,7 @@ public sealed class GtkSkiaSurfaceWidget : IDisposable
if (!char.IsControl(c) || c == '\r' || c == '\n' || c == '\t')
{
string text = c.ToString();
Console.WriteLine($"[GtkSkiaSurfaceWidget] TextInput: '{text}' (keyval={keyval}, unicode={unicode})");
DiagnosticLog.Debug("GtkSkiaSurfaceWidget", $"TextInput: '{text}' (keyval={keyval}, unicode={unicode})");
TextInput?.Invoke(this, text);
}
}

View File

@@ -5,6 +5,7 @@ using SkiaSharp;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Window;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Platform.Linux.Services;
using System.Runtime.InteropServices;
namespace Microsoft.Maui.Platform.Linux.Rendering;
@@ -169,8 +170,16 @@ public class SkiaRenderingEngine : IDisposable
// Measure and arrange
var availableSize = new Size(Width, Height);
rootView.Measure(availableSize);
rootView.Arrange(new Rect(0, 0, Width, Height));
try
{
rootView.Measure(availableSize);
rootView.Arrange(new Rect(0, 0, Width, Height));
}
catch (Exception ex)
{
DiagnosticLog.Error("SkiaRenderingEngine", "Exception during Measure/Arrange", ex);
return;
}
// Determine what to redraw
List<SKRect> regionsToRedraw;
@@ -199,16 +208,37 @@ public class SkiaRenderingEngine : IDisposable
// Render dirty regions
foreach (var region in regionsToRedraw)
{
RenderRegion(rootView, region, isFullRedraw);
try
{
RenderRegion(rootView, region, isFullRedraw);
}
catch (Exception ex)
{
DiagnosticLog.Error("SkiaRenderingEngine", $"Exception rendering region {region}", ex);
}
}
// Draw popup overlays (always on top, full redraw)
SkiaView.DrawPopupOverlays(_canvas);
try
{
SkiaView.DrawPopupOverlays(_canvas);
}
catch (Exception ex)
{
DiagnosticLog.Error("SkiaRenderingEngine", "Exception drawing popup overlays", ex);
}
// Draw modal dialogs and context menus on top of everything
if (LinuxDialogService.HasActiveDialog || LinuxDialogService.HasContextMenu)
try
{
LinuxDialogService.DrawDialogs(_canvas, new SKRect(0, 0, Width, Height));
if (LinuxDialogService.HasActiveDialog || LinuxDialogService.HasContextMenu)
{
LinuxDialogService.DrawDialogs(_canvas, new SKRect(0, 0, Width, Height));
}
}
catch (Exception ex)
{
DiagnosticLog.Error("SkiaRenderingEngine", "Exception drawing dialogs", ex);
}
_canvas.Flush();
@@ -234,7 +264,14 @@ public class SkiaRenderingEngine : IDisposable
_canvas.DrawRect(region, clearPaint);
// Draw the view tree (views will naturally clip to their bounds)
rootView.Draw(_canvas);
try
{
rootView.Draw(_canvas);
}
catch (Exception ex)
{
DiagnosticLog.Error("SkiaRenderingEngine", "Exception during view Draw", ex);
}
_canvas.Restore();
}