Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 55 additions & 53 deletions src/Uno.Templates/content/unoapp/MyExtensionsApp.1/App.blank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,79 +106,81 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
}
//+:cnd:noEmit
#if (useLoggingFallback)

/// <summary>
/// Configures global Uno Platform logging
/// </summary>
public static void InitializeLogging()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping the original (single) InitializeLogging method will be simpler and will be consistent across both blank and recommended templates.
In fact, we could even move this to App.logging.cs or similar in order to make it clearer that's where logging is configured.

private static ILoggingBuilder ConfigureLogging(ILoggingBuilder builder, LogLevel defaultLogLevel)
{
//-:cnd:noEmit
#if DEBUG
// Logging is disabled by default for release builds, as it incurs a significant
// initialization cost from Microsoft.Extensions.Logging setup. If startup performance
// is a concern for your application, keep this disabled. If you're running on the web or
// desktop targets, you can use URL or command line parameters to enable it.
//
// For more performance documentation: https://platform.uno/docs/articles/Uno-UI-Performance.html

var factory = LoggerFactory.Create(builder =>
{
#if __WASM__
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
#elif __IOS__
builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider());
builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider());

// Log to the Visual Studio Debug console
builder.AddConsole();
#else
builder.AddConsole();
#endif
// Log to the Visual Studio Debug console
builder.AddConsole();
#else // !__WASM__ && !__IOS__
builder.AddConsole();
#endif // __WASM__ || __IOS__

// Exclude logs below this level
builder.SetMinimumLevel(LogLevel.Information);
// Exclude logs below this level
builder.SetMinimumLevel(defaultLogLevel);

// Default filters for Uno Platform namespaces
builder.AddFilter("Uno", LogLevel.Warning);
builder.AddFilter("Windows", LogLevel.Warning);
builder.AddFilter("Microsoft", LogLevel.Warning);
// Default filters for Uno Platform namespaces
builder.AddFilter("Uno", LogLevel.Warning);
builder.AddFilter("Windows", LogLevel.Warning);
builder.AddFilter("Microsoft", LogLevel.Warning);

// Generic Xaml events
// builder.AddFilter("Microsoft.UI.Xaml", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.VisualStateGroup", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.StateTriggerBase", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.UIElement", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.FrameworkElement", LogLevel.Trace );
// Generic Xaml events
// builder.AddFilter("Microsoft.UI.Xaml", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.VisualStateGroup", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.StateTriggerBase", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.UIElement", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.FrameworkElement", LogLevel.Trace );

// Layouter specific messages
// builder.AddFilter("Microsoft.UI.Xaml.Controls", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Layouter", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Panel", LogLevel.Debug );
// Layouter specific messages
// builder.AddFilter("Microsoft.UI.Xaml.Controls", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Layouter", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Panel", LogLevel.Debug );

// builder.AddFilter("Windows.Storage", LogLevel.Debug );
// builder.AddFilter("Windows.Storage", LogLevel.Debug );

// Binding related messages
// builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug );
// Binding related messages
// builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug );

// Binder memory references tracking
// builder.AddFilter("Uno.UI.DataBinding.BinderReferenceHolder", LogLevel.Debug );
// Binder memory references tracking
// builder.AddFilter("Uno.UI.DataBinding.BinderReferenceHolder", LogLevel.Debug );

// DevServer and HotReload related
// builder.AddFilter("Uno.UI.RemoteControl", LogLevel.Information);
// DevServer and HotReload related
// builder.AddFilter("Uno.UI.RemoteControl", LogLevel.Information);

// Debug JS interop
// builder.AddFilter("Uno.Foundation.WebAssemblyRuntime", LogLevel.Debug );
});
// Debug JS interop
// builder.AddFilter("Uno.Foundation.WebAssemblyRuntime", LogLevel.Debug );

global::Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = factory;
return builder;
}

/// <summary>
/// Configures global Uno Platform logging
/// </summary>
public static void InitializeLogging()
{
#if DEBUG
// Logging is disabled by default for release builds, as it incurs a significant
// initialization cost from Microsoft.Extensions.Logging setup. If startup performance
// is a concern for your application, keep this disabled. If you're running on the web or
// desktop targets, you can use URL or command line parameters to enable it.
//
// For more performance documentation: https://platform.uno/docs/articles/Uno-UI-Performance.html

var factory = LoggerFactory.Create(builder => ConfigureLogging(builder, LogLevel.Information));

// LogExtensionPoint.AmbientLoggerFactory is used by `Uno.dll` et al for
// logging messages, such as from `NativeDispatcher`.
global::Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = factory;
#if HAS_UNO
global::Uno.UI.Adapter.Microsoft.Extensions.Logging.LoggingAdapter.Initialize();
#endif
#endif
//+:cnd:noEmit
#endif // HAS_UNO
#endif // DEBUG
}
#endif
}
127 changes: 102 additions & 25 deletions src/Uno.Templates/content/unoapp/MyExtensionsApp.1/App.recommended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,15 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
#if useLogging
.UseLogging(configure: (context, logBuilder) =>
{
// Configure log levels for different categories of logging
logBuilder
.SetMinimumLevel(
context.HostingEnvironment.IsDevelopment() ?
ConfigureLogging(
logBuilder,
// Configure log levels for different categories of logging
context.HostingEnvironment.IsDevelopment() ?
LogLevel.Information :
LogLevel.Warning)
.CoreLogLevel(LogLevel.Warning);

// Default filters for core Uno Platform namespaces
.CoreLogLevel(LogLevel.Warning);

// Uno Platform namespace filter groups
// Uncomment individual methods to see more detailed logging
//// Generic Xaml events
//logBuilder.XamlLogLevel(LogLevel.Debug);
//// Layout specific messages
//logBuilder.XamlLayoutLogLevel(LogLevel.Debug);
//// Storage messages
//logBuilder.StorageLogLevel(LogLevel.Debug);
//// Binding related messages
//logBuilder.XamlBindingLogLevel(LogLevel.Debug);
//// Binder memory references tracking
//logBuilder.BinderMemoryReferenceLogLevel(LogLevel.Debug);
//// DevServer and HotReload related
//logBuilder.HotReloadCoreLogLevel(LogLevel.Information);
//// Debug JS interop
//logBuilder.WebAssemblyLogLevel(LogLevel.Debug);

}, enableUnoLogging: true)
}, enableUnoLogging: false)
#endif
#if useSerilog
.UseSerilog(consoleLoggingEnabled: true, fileLoggingEnabled: true)
Expand Down Expand Up @@ -311,4 +292,100 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
#endif
}
#endif

/// <summary>
/// Configures global Uno Platform logging
/// </summary>
private static ILoggingBuilder ConfigureLogging(ILoggingBuilder builder, LogLevel defaultLogLevel)
{
#if __WASM__
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
#elif __IOS__
builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider());

// Log to the Visual Studio Debug console
builder.AddConsole();
#else // !__WASM__ && !__IOS__
builder.AddConsole();
#endif // __WASM__ || __IOS__

// Exclude logs below this level
builder.SetMinimumLevel(defaultLogLevel);

// Default filters for Uno Platform namespaces
builder.AddFilter("Uno", LogLevel.Warning);
builder.AddFilter("Windows", LogLevel.Warning);
builder.AddFilter("Microsoft", LogLevel.Warning);

// Generic Xaml events
// builder.AddFilter("Microsoft.UI.Xaml", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.VisualStateGroup", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.StateTriggerBase", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.UIElement", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.FrameworkElement", LogLevel.Trace );

// Layouter specific messages
// builder.AddFilter("Microsoft.UI.Xaml.Controls", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Layouter", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Controls.Panel", LogLevel.Debug );

// builder.AddFilter("Windows.Storage", LogLevel.Debug );

// Binding related messages
// builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug );
// builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug );

// Binder memory references tracking
// builder.AddFilter("Uno.UI.DataBinding.BinderReferenceHolder", LogLevel.Debug );

// DevServer and HotReload related
// builder.AddFilter("Uno.UI.RemoteControl", LogLevel.Information);

// Debug JS interop
// builder.AddFilter("Uno.Foundation.WebAssemblyRuntime", LogLevel.Debug );

// Uno Platform namespace filter groups
// Uncomment individual methods to see more detailed logging
//// Generic Xaml events
//builder.XamlLogLevel(LogLevel.Debug);
//// Layout specific messages
//builder.XamlLayoutLogLevel(LogLevel.Debug);
//// Storage messages
//builder.StorageLogLevel(LogLevel.Debug);
//// Binding related messages
//builder.XamlBindingLogLevel(LogLevel.Debug);
//// Binder memory references tracking
//builder.BinderMemoryReferenceLogLevel(LogLevel.Debug);
//// DevServer and HotReload related
//builder.HotReloadCoreLogLevel(LogLevel.Information);
//// Debug JS interop
//builder.WebAssemblyLogLevel(LogLevel.Debug);

return builder;
}

/// <summary>
/// Configures global Uno Platform logging
/// </summary>
public static void InitializeLogging()
{
#if DEBUG
// Logging is disabled by default for release builds, as it incurs a significant
// initialization cost from Microsoft.Extensions.Logging setup. If startup performance
// is a concern for your application, keep this disabled. If you're running on the web or
// desktop targets, you can use URL or command line parameters to enable it.
//
// For more performance documentation: https://platform.uno/docs/articles/Uno-UI-Performance.html

var factory = LoggerFactory.Create(builder => ConfigureLogging(builder, LogLevel.Information));

// LogExtensionPoint.AmbientLoggerFactory is used by `Uno.dll` et al for
// logging messages, such as from `NativeDispatcher`.
// Some of these can occur *before* Dependency Injection `.UseLogging()` executes.
global::Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = factory;
#if HAS_UNO
global::Uno.UI.Adapter.Microsoft.Extensions.Logging.LoggingAdapter.Initialize();
#endif // HAS_UNO
#endif // DEBUG
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ internal class Program
[STAThread]
public static void Main(string[] args)
{
//+:cnd:noEmit
#if (!useDependencyInjection && useLoggingFallback)
App.InitializeLogging();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#endif
//-:cnd:noEmit

var host = UnoPlatformHostBuilder.Create()
.App(() => new App())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ public class Program
{
public static async Task Main(string[] args)
{
//+:cnd:noEmit
#if (!useDependencyInjection && useLoggingFallback)
App.InitializeLogging();

#endif
//-:cnd:noEmit
var host = UnoPlatformHostBuilder.Create()
.App(() => new App())
.UseWebAssembly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ public class EntryPoint
// This is the main entry point of the application.
public static void Main(string[] args)
{
//+:cnd:noEmit
#if (!useDependencyInjection && useLoggingFallback)
App.InitializeLogging();

#endif
//-:cnd:noEmit
var host = UnoPlatformHostBuilder.Create()
.App(() => new App())
.UseAppleUIKit()
Expand Down
Loading