Search code examples
c#.netloggingavaloniauiavalonia

Is there any cross-platform tool for AvaloniaUI to log events?


What logger should i use at AvaloniaUI? I know about Serilog, but is it cross-platform? Is there any built-in tool for this?

Moreover i need to log info to the .log file. This must be cross-platform (Windows, Linux and MacOS).


Solution

  • Avalonia can log warnings and errors using System.Diagnostics.Trace. To enable logging the LogToTrace method call should be present in your Program.cs file:

    public static AppBuilder BuildAvaloniaApp()
        => AppBuilder.Configure<App>()
            .UsePlatformDetect()
            .LogToTrace();
    

    And yes, you can log to file.

    By default these trace messages would be logger to your IDE output window. If you want to re-route these messages to different location, use API provided by System.Diagnostics.Trace.

    See more info about this at official site.