Skip to content

Commit

Permalink
perf: Build only one logger for static style methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 20, 2021
1 parent 5df799e commit f4651c9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Uno.UI/UI/Xaml/Style/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Windows.UI.Xaml
[Markup.ContentProperty(Name = "Setters")]
public partial class Style
{
private static ILogger _logger = typeof(Style).Log();

private delegate void ApplyToHandler(DependencyObject instance);

public delegate Style StyleProviderHandler();
Expand Down Expand Up @@ -226,24 +228,24 @@ Style ProvideStyle()
if (style == null && !useUWPDefaultStyles)
{

if (typeof(Style).Log().IsEnabled(LogLevel.Debug))
if (_logger.IsEnabled(LogLevel.Debug))
{
typeof(Style).Log().LogDebug($"No native style found for type {type}, falling back on UWP style");
_logger.LogDebug($"No native style found for type {type}, falling back on UWP style");
}

// If no native style found, fall back on UWP style
style = GetDefaultStyleForType(type, useUWPDefaultStyles: true);
}

if (typeof(Style).Log().IsEnabled(LogLevel.Debug))
if (_logger.IsEnabled(LogLevel.Debug))
{
if (style != null)
{
typeof(Style).Log().LogDebug($"Returning {(useUWPDefaultStyles ? "UWP" : "native")} style {style} for type {type}");
_logger.LogDebug($"Returning {(useUWPDefaultStyles ? "UWP" : "native")} style {style} for type {type}");
}
else
{
typeof(Style).Log().LogDebug($"No {(useUWPDefaultStyles ? "UWP" : "native")} style found for type {type}");
_logger.LogDebug($"No {(useUWPDefaultStyles ? "UWP" : "native")} style found for type {type}");
}
}

Expand Down

0 comments on commit f4651c9

Please sign in to comment.