简体   繁体   中英

Unable to log to console with Uno Platform / UWP Head

How is (cross-platform) logging achieved with Uno? (to console, mainly)

I'm using Visual Studio, starting the UWP Head, and when i try to write something to the log, I'm expecting it to appear in Visual Studio Output windows / Uno Platform output, but nothing shows up there.

I'm using the following code (that i found in various repositories, as a supposed 'standard' way to log), in a UWP page 'code behind' code:

this.Log().LogInformation("My log");

but, as I said, nothing appears in the output windows.

The documentation says that to enable console logging you should use the following code:

Uno.Logging.LogManager.LoggerSelector = Uno.Logging.ConsoleLogger.Instance.GetLog;
Uno.Logging.ConsoleLogger.Instance.LogLevel = Uno.Logging.LogLevel.Warn;

Uno.Logging.ConsoleLogger.Instance.Filter = (level, name, message, exception) =>
{
    // Provides a list of loggers that should be displayed to the console
    var passList = new[] {
        "Windows.UI.Xaml.VisualStateManager",
        "Windows.UI.Xaml.VisualStateGroup",
        "Windows.UI.Xaml.Controls.RadioButton",
    };

    return passList.Any(n => name.StartsWith(n))
        ? Uno.Logging.ConsoleLogger.FilterResult.Pass : Uno.Logging.ConsoleLogger.FilterResult.Ignore;
};

but the types Uno.Logging.LogManager and Uno.Logging.ConsoleLogger are not existent. Are they defined in additional libraries/nuGet packages? And where does this code should be placed?

EDIT:

This happens only with the UWP head. With the Wasm head, the log messages show correctly in browser's console, and with Android head (running in an emulator) they show up in Visual Studio's Output/Debug window. Can't try the iOS head, sorry.

Environment:

Visual Studio 2019            16.7.3
Uno.Core                      2.0.0
Uno.UI                        3.0.17
Uno.UI.RemoteControl          3.0.17
Uno.UI.WebAssembly            3.0.17
Uno.UniversalImageLoader      1.9.32
Uno.Wasm.Bootstrap            1.3.4
Uno.Wasm.Bootstrap.DevServer  1.3.4

When you are calling this.Log() , it will capture the fully qualified named of the this 's type.

If you add the namespace of this type to the passList , it should work.

When you create a project using the template, you'll see a ConfigureFilters method in the App.xaml.cs file. Add you namespace there in the .WithFilter() call.

Example of such call here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM