Skip to content

Commit 9d43685

Browse files
committed
Implemented Avalonia debug logger without trace facility
1 parent 95b040d commit 9d43685

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Duplicati/GUI/Duplicati.GUI.TrayIcon/AvaloniaRunner.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Avalonia;
2828
using Avalonia.Controls;
2929
using Avalonia.Controls.ApplicationLifetimes;
30+
using Avalonia.Logging;
3031
using Avalonia.Media.Imaging;
3132
using Avalonia.Platform;
3233
using Avalonia.Themes.Fluent;
@@ -98,9 +99,9 @@ protected override void Run(string[] args)
9899
builder = builder.LogToTrace();
99100
#else
100101
if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "1")
101-
builder = builder.LogToTrace();
102+
Logger.Sink = new ConsoleLogSink(LogEventLevel.Information);
102103
else if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "2")
103-
builder = builder.LogToTrace(Avalonia.Logging.LogEventLevel.Verbose);
104+
Logger.Sink = new ConsoleLogSink(LogEventLevel.Verbose);
104105
#endif
105106

106107
application = builder.Instance as AvaloniaApp;
@@ -402,4 +403,19 @@ public override void OnFrameworkInitializationCompleted()
402403
base.OnFrameworkInitializationCompleted();
403404
}
404405
}
406+
407+
internal class ConsoleLogSink(LogEventLevel minLevel) : ILogSink
408+
{
409+
private readonly LogEventLevel _minLevel = minLevel;
410+
411+
public bool IsEnabled(LogEventLevel level, string area)
412+
=> level >= _minLevel;
413+
414+
public void Log(LogEventLevel level, string area, object source, string messageTemplate)
415+
=> Log(level, area, source, messageTemplate, null);
416+
417+
public void Log(LogEventLevel level, string area, object source, string messageTemplate, params object[] propertyValues)
418+
=> Console.WriteLine($"Avalonia [{level}]: {source} {messageTemplate} {string.Join(" ", propertyValues)}");
419+
}
420+
405421
}

0 commit comments

Comments
 (0)