|
27 | 27 | using Avalonia;
|
28 | 28 | using Avalonia.Controls;
|
29 | 29 | using Avalonia.Controls.ApplicationLifetimes;
|
| 30 | +using Avalonia.Logging; |
30 | 31 | using Avalonia.Media.Imaging;
|
31 | 32 | using Avalonia.Platform;
|
32 | 33 | using Avalonia.Themes.Fluent;
|
@@ -98,9 +99,9 @@ protected override void Run(string[] args)
|
98 | 99 | builder = builder.LogToTrace();
|
99 | 100 | #else
|
100 | 101 | if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "1")
|
101 |
| - builder = builder.LogToTrace(); |
| 102 | + Logger.Sink = new ConsoleLogSink(LogEventLevel.Information); |
102 | 103 | else if (Environment.GetEnvironmentVariable("DEBUG_AVALONIA") == "2")
|
103 |
| - builder = builder.LogToTrace(Avalonia.Logging.LogEventLevel.Verbose); |
| 104 | + Logger.Sink = new ConsoleLogSink(LogEventLevel.Verbose); |
104 | 105 | #endif
|
105 | 106 |
|
106 | 107 | application = builder.Instance as AvaloniaApp;
|
@@ -402,4 +403,19 @@ public override void OnFrameworkInitializationCompleted()
|
402 | 403 | base.OnFrameworkInitializationCompleted();
|
403 | 404 | }
|
404 | 405 | }
|
| 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 | + |
405 | 421 | }
|
0 commit comments