Browse Source

Parameterize logger on area as well as level.

So we can filter our more logging calls early.
pull/4135/head
Steven Kirk 6 years ago
parent
commit
479d480ad9
  1. 2
      samples/RenderDemo/App.xaml.cs
  2. 1
      samples/VirtualizationDemo/Program.cs
  3. 12
      src/Avalonia.Base/AvaloniaObject.cs
  4. 3
      src/Avalonia.Base/Data/Core/BindingExpression.cs
  5. 7
      src/Avalonia.Base/Logging/DebugLogSink.cs
  6. 5
      src/Avalonia.Base/Logging/ILogSink.cs
  7. 17
      src/Avalonia.Base/Logging/Logger.cs
  8. 32
      src/Avalonia.Base/Logging/ParametrizedLogger.cs
  9. 3
      src/Avalonia.Base/Reactive/TypedBindingAdapter.cs
  10. 4
      src/Avalonia.Controls/DropDown.cs
  11. 2
      src/Avalonia.Controls/Primitives/TemplatedControl.cs
  12. 3
      src/Avalonia.Controls/TopLevel.cs
  13. 7
      src/Avalonia.Layout/LayoutManager.cs
  14. 8
      src/Avalonia.Layout/Layoutable.cs
  15. 2
      src/Avalonia.Logging.Serilog/SerilogLogger.cs
  16. 2
      src/Avalonia.OpenGL/EglGlPlatformFeature.cs
  17. 8
      src/Avalonia.OpenGL/OpenGlControlBase.cs
  18. 3
      src/Avalonia.Styling/StyledElement.cs
  19. 6
      src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs
  20. 2
      src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
  21. 2
      src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs
  22. 4
      src/Avalonia.Visuals/Rendering/RenderLoop.cs
  23. 7
      src/Avalonia.Visuals/Visual.cs
  24. 2
      src/Avalonia.X11/Glx/GlxPlatformFeature.cs
  25. 3
      src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs
  26. 3
      src/Markup/Avalonia.Markup/Markup/Data/DelayedBinding.cs
  27. 3
      src/Windows/Avalonia.Direct2D1/Media/StreamGeometryContextImpl.cs
  28. 2
      tests/Avalonia.UnitTests/TestLogSink.cs

2
samples/RenderDemo/App.xaml.cs

@ -1,5 +1,4 @@
using Avalonia; using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
@ -22,6 +21,5 @@ namespace RenderDemo
.UsePlatformDetect() .UsePlatformDetect()
.UseReactiveUI() .UseReactiveUI()
.LogToDebug(); .LogToDebug();
} }
} }

1
samples/VirtualizationDemo/Program.cs

@ -1,7 +1,6 @@
using System; using System;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Logging.Serilog;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
using Serilog; using Serilog;

12
src/Avalonia.Base/AvaloniaObject.cs

@ -421,8 +421,7 @@ namespace Avalonia
throw new ArgumentException($"The property {property.Name} is readonly."); throw new ArgumentException($"The property {property.Name} is readonly.");
} }
Logger.TryGet(LogEventLevel.Verbose)?.Log( Logger.TryGet(LogEventLevel.Verbose, LogArea.Property)?.Log(
LogArea.Property,
this, this,
"Bound {Property} to {Binding} with priority LocalValue", "Bound {Property} to {Binding} with priority LocalValue",
property, property,
@ -501,8 +500,7 @@ namespace Avalonia
if (change.IsEffectiveValueChange) if (change.IsEffectiveValueChange)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log( Logger.TryGet(LogEventLevel.Verbose, LogArea.Property)?.Log(
LogArea.Property,
this, this,
"{Property} changed from {$Old} to {$Value} with priority {Priority}", "{Property} changed from {$Old} to {$Value} with priority {Priority}",
property, property,
@ -586,8 +584,7 @@ namespace Avalonia
/// <param name="e">The binding error.</param> /// <param name="e">The binding error.</param>
protected internal virtual void LogBindingError(AvaloniaProperty property, Exception e) protected internal virtual void LogBindingError(AvaloniaProperty property, Exception e)
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Property)?.Log(
LogArea.Binding,
this, this,
"Error in binding to {Target}.{Property}: {Message}", "Error in binding to {Target}.{Property}: {Message}",
this, this,
@ -857,8 +854,7 @@ namespace Avalonia
/// <param name="priority">The priority.</param> /// <param name="priority">The priority.</param>
private void LogPropertySet<T>(AvaloniaProperty<T> property, T value, BindingPriority priority) private void LogPropertySet<T>(AvaloniaProperty<T> property, T value, BindingPriority priority)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log( Logger.TryGet(LogEventLevel.Verbose, LogArea.Property)?.Log(
LogArea.Property,
this, this,
"Set {Property} to {$Value} with priority {Priority}", "Set {Property} to {$Value} with priority {Priority}",
property, property,

3
src/Avalonia.Base/Data/Core/BindingExpression.cs

@ -168,8 +168,7 @@ namespace Avalonia.Data.Core
} }
else else
{ {
Logger.TryGet(LogEventLevel.Error)?.Log( Logger.TryGet(LogEventLevel.Error, LogArea.Binding)?.Log(
LogArea.Binding,
this, this,
"Could not convert FallbackValue {FallbackValue} to {Type}", "Could not convert FallbackValue {FallbackValue} to {Type}",
_fallbackValue, _fallbackValue,

7
src/Avalonia.Base/Logging/DebugLogSink.cs

@ -19,7 +19,10 @@ namespace Avalonia.Logging
_areas = areas?.Count > 0 ? areas : null; _areas = areas?.Count > 0 ? areas : null;
} }
public bool IsEnabled(LogEventLevel level) => level >= _level; public bool IsEnabled(LogEventLevel level, string area)
{
return level >= _level && (_areas?.Contains(area) ?? true);
}
public void Log(LogEventLevel level, string area, object source, string messageTemplate) public void Log(LogEventLevel level, string area, object source, string messageTemplate)
{ {
@ -61,8 +64,6 @@ namespace Avalonia.Logging
} }
} }
private bool IsEnabled(LogEventLevel level, string area) => IsEnabled(level) && (_areas?.Contains(area) ?? true);
private static string Format<T0, T1, T2>( private static string Format<T0, T1, T2>(
string area, string area,
string template, string template,

5
src/Avalonia.Base/Logging/ILogSink.cs

@ -6,11 +6,12 @@ namespace Avalonia.Logging
public interface ILogSink public interface ILogSink
{ {
/// <summary> /// <summary>
/// Checks if given log level is enabled. /// Checks if given log level and area is enabled.
/// </summary> /// </summary>
/// <param name="level">The log event level.</param> /// <param name="level">The log event level.</param>
/// <param name="area">The log area.</param>
/// <returns><see langword="true"/> if given log level is enabled.</returns> /// <returns><see langword="true"/> if given log level is enabled.</returns>
bool IsEnabled(LogEventLevel level); bool IsEnabled(LogEventLevel level, string area);
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.

17
src/Avalonia.Base/Logging/Logger.cs

@ -14,36 +14,39 @@ namespace Avalonia.Logging
/// Checks if given log level is enabled. /// Checks if given log level is enabled.
/// </summary> /// </summary>
/// <param name="level">The log event level.</param> /// <param name="level">The log event level.</param>
/// <param name="area">The log area.</param>
/// <returns><see langword="true"/> if given log level is enabled.</returns> /// <returns><see langword="true"/> if given log level is enabled.</returns>
public static bool IsEnabled(LogEventLevel level) public static bool IsEnabled(LogEventLevel level, string area)
{ {
return Sink?.IsEnabled(level) == true; return Sink?.IsEnabled(level, area) == true;
} }
/// <summary> /// <summary>
/// Returns parametrized logging sink if given log level is enabled. /// Returns parametrized logging sink if given log level is enabled.
/// </summary> /// </summary>
/// <param name="level">The log event level.</param> /// <param name="level">The log event level.</param>
/// <param name="area">The area that the event originates from.</param>
/// <returns>Log sink or <see langword="null"/> if log level is not enabled.</returns> /// <returns>Log sink or <see langword="null"/> if log level is not enabled.</returns>
public static ParametrizedLogger? TryGet(LogEventLevel level) public static ParametrizedLogger? TryGet(LogEventLevel level, string area)
{ {
if (!IsEnabled(level)) if (!IsEnabled(level, area))
{ {
return null; return null;
} }
return new ParametrizedLogger(Sink, level); return new ParametrizedLogger(Sink, level, area);
} }
/// <summary> /// <summary>
/// Returns parametrized logging sink if given log level is enabled. /// Returns parametrized logging sink if given log level is enabled.
/// </summary> /// </summary>
/// <param name="level">The log event level.</param> /// <param name="level">The log event level.</param>
/// <param name="area">The area that the event originates from.</param>
/// <param name="outLogger">Log sink that is valid only if method returns <see langword="true"/>.</param> /// <param name="outLogger">Log sink that is valid only if method returns <see langword="true"/>.</param>
/// <returns><see langword="true"/> if logger was obtained successfully.</returns> /// <returns><see langword="true"/> if logger was obtained successfully.</returns>
public static bool TryGet(LogEventLevel level, out ParametrizedLogger outLogger) public static bool TryGet(LogEventLevel level, string area, out ParametrizedLogger outLogger)
{ {
ParametrizedLogger? logger = TryGet(level); ParametrizedLogger? logger = TryGet(level, area);
outLogger = logger.GetValueOrDefault(); outLogger = logger.GetValueOrDefault();

32
src/Avalonia.Base/Logging/ParametrizedLogger.cs

@ -9,11 +9,13 @@ namespace Avalonia.Logging
{ {
private readonly ILogSink _sink; private readonly ILogSink _sink;
private readonly LogEventLevel _level; private readonly LogEventLevel _level;
private readonly string _area;
public ParametrizedLogger(ILogSink sink, LogEventLevel level) public ParametrizedLogger(ILogSink sink, LogEventLevel level, string area)
{ {
_sink = sink; _sink = sink;
_level = level; _level = level;
_area = area;
} }
/// <summary> /// <summary>
@ -24,58 +26,51 @@ namespace Avalonia.Logging
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log( public void Log(
string area,
object source, object source,
string messageTemplate) string messageTemplate)
{ {
_sink.Log(_level, area, source, messageTemplate); _sink.Log(_level, _area, source, messageTemplate);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0>( public void Log<T0>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0) T0 propertyValue0)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0); _sink.Log(_level, _area, source, messageTemplate, propertyValue0);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
/// <param name="propertyValue1">Message property value.</param> /// <param name="propertyValue1">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0, T1>( public void Log<T0, T1>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0, T0 propertyValue0,
T1 propertyValue1) T1 propertyValue1)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0, propertyValue1); _sink.Log(_level, _area, source, messageTemplate, propertyValue0, propertyValue1);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
@ -83,20 +78,18 @@ namespace Avalonia.Logging
/// <param name="propertyValue2">Message property value.</param> /// <param name="propertyValue2">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0, T1, T2>( public void Log<T0, T1, T2>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0, T0 propertyValue0,
T1 propertyValue1, T1 propertyValue1,
T2 propertyValue2) T2 propertyValue2)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2); _sink.Log(_level, _area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
@ -105,7 +98,6 @@ namespace Avalonia.Logging
/// <param name="propertyValue3">Message property value.</param> /// <param name="propertyValue3">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0, T1, T2, T3>( public void Log<T0, T1, T2, T3>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0, T0 propertyValue0,
@ -113,13 +105,12 @@ namespace Avalonia.Logging
T2 propertyValue2, T2 propertyValue2,
T3 propertyValue3) T3 propertyValue3)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3); _sink.Log(_level, _area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
@ -129,7 +120,6 @@ namespace Avalonia.Logging
/// <param name="propertyValue4">Message property value.</param> /// <param name="propertyValue4">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0, T1, T2, T3, T4>( public void Log<T0, T1, T2, T3, T4>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0, T0 propertyValue0,
@ -138,13 +128,12 @@ namespace Avalonia.Logging
T3 propertyValue3, T3 propertyValue3,
T4 propertyValue4) T4 propertyValue4)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3, propertyValue4); _sink.Log(_level, _area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3, propertyValue4);
} }
/// <summary> /// <summary>
/// Logs an event. /// Logs an event.
/// </summary> /// </summary>
/// <param name="area">The area that the event originates.</param>
/// <param name="source">The object from which the event originates.</param> /// <param name="source">The object from which the event originates.</param>
/// <param name="messageTemplate">The message template.</param> /// <param name="messageTemplate">The message template.</param>
/// <param name="propertyValue0">Message property value.</param> /// <param name="propertyValue0">Message property value.</param>
@ -155,7 +144,6 @@ namespace Avalonia.Logging
/// <param name="propertyValue5">Message property value.</param> /// <param name="propertyValue5">Message property value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log<T0, T1, T2, T3, T4, T5>( public void Log<T0, T1, T2, T3, T4, T5>(
string area,
object source, object source,
string messageTemplate, string messageTemplate,
T0 propertyValue0, T0 propertyValue0,
@ -165,7 +153,7 @@ namespace Avalonia.Logging
T4 propertyValue4, T4 propertyValue4,
T5 propertyValue5) T5 propertyValue5)
{ {
_sink.Log(_level, area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3, propertyValue4, propertyValue5); _sink.Log(_level, _area, source, messageTemplate, propertyValue0, propertyValue1, propertyValue2, propertyValue3, propertyValue4, propertyValue5);
} }
} }
} }

3
src/Avalonia.Base/Reactive/TypedBindingAdapter.cs

@ -32,8 +32,7 @@ namespace Avalonia.Reactive
} }
catch (InvalidCastException e) catch (InvalidCastException e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log( Logger.TryGet(LogEventLevel.Error, LogArea.Binding)?.Log(
LogArea.Binding,
_target, _target,
"Binding produced invalid value for {$Property} ({$PropertyType}): {$Value} ({$ValueType})", "Binding produced invalid value for {$Property} ({$PropertyType}): {$Value} ({$ValueType})",
_property.Name, _property.Name,

4
src/Avalonia.Controls/DropDown.cs

@ -9,7 +9,7 @@ namespace Avalonia.Controls
{ {
public DropDown() public DropDown()
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log(LogArea.Control, this, "DropDown is deprecated: Use ComboBox"); Logger.TryGet(LogEventLevel.Warning, LogArea.Control)?.Log(this, "DropDown is deprecated: Use ComboBox");
} }
Type IStyleable.StyleKey => typeof(ComboBox); Type IStyleable.StyleKey => typeof(ComboBox);
@ -20,7 +20,7 @@ namespace Avalonia.Controls
{ {
public DropDownItem() public DropDownItem()
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log(LogArea.Control, this, "DropDownItem is deprecated: Use ComboBoxItem"); Logger.TryGet(LogEventLevel.Warning, LogArea.Control)?.Log(this, "DropDownItem is deprecated: Use ComboBoxItem");
} }
Type IStyleable.StyleKey => typeof(ComboBoxItem); Type IStyleable.StyleKey => typeof(ComboBoxItem);

2
src/Avalonia.Controls/Primitives/TemplatedControl.cs

@ -252,7 +252,7 @@ namespace Avalonia.Controls.Primitives
if (template != null) if (template != null)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Control, this, "Creating control template"); Logger.TryGet(LogEventLevel.Verbose, LogArea.Control)?.Log(this, "Creating control template");
var (child, nameScope) = template.Build(this); var (child, nameScope) = template.Build(this);
ApplyTemplatedParent(child); ApplyTemplatedParent(child);

3
src/Avalonia.Controls/TopLevel.cs

@ -452,8 +452,7 @@ namespace Avalonia.Controls
if (result == null) if (result == null)
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Control)?.Log(
LogArea.Control,
this, this,
"Could not create {Service} : maybe Application.RegisterServices() wasn't called?", "Could not create {Service} : maybe Application.RegisterServices() wasn't called?",
typeof(T)); typeof(T));

7
src/Avalonia.Layout/LayoutManager.cs

@ -76,12 +76,11 @@ namespace Avalonia.Layout
Stopwatch stopwatch = null; Stopwatch stopwatch = null;
const LogEventLevel timingLogLevel = LogEventLevel.Information; const LogEventLevel timingLogLevel = LogEventLevel.Information;
bool captureTiming = Logger.IsEnabled(timingLogLevel); bool captureTiming = Logger.IsEnabled(timingLogLevel, LogArea.Layout);
if (captureTiming) if (captureTiming)
{ {
Logger.TryGet(timingLogLevel)?.Log( Logger.TryGet(timingLogLevel, LogArea.Layout)?.Log(
LogArea.Layout,
this, this,
"Started layout pass. To measure: {Measure} To arrange: {Arrange}", "Started layout pass. To measure: {Measure} To arrange: {Arrange}",
_toMeasure.Count, _toMeasure.Count,
@ -119,7 +118,7 @@ namespace Avalonia.Layout
{ {
stopwatch.Stop(); stopwatch.Stop();
Logger.TryGet(timingLogLevel)?.Log(LogArea.Layout, this, "Layout pass finished in {Time}", stopwatch.Elapsed); Logger.TryGet(timingLogLevel, LogArea.Layout)?.Log(this, "Layout pass finished in {Time}", stopwatch.Elapsed);
} }
} }

8
src/Avalonia.Layout/Layoutable.cs

@ -326,7 +326,7 @@ namespace Avalonia.Layout
DesiredSize = desiredSize; DesiredSize = desiredSize;
_previousMeasure = availableSize; _previousMeasure = availableSize;
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Layout, this, "Measure requested {DesiredSize}", DesiredSize); Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Measure requested {DesiredSize}", DesiredSize);
if (DesiredSize != previousDesiredSize) if (DesiredSize != previousDesiredSize)
{ {
@ -353,7 +353,7 @@ namespace Avalonia.Layout
if (!IsArrangeValid || _previousArrange != rect) if (!IsArrangeValid || _previousArrange != rect)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Layout, this, "Arrange to {Rect} ", rect); Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Arrange to {Rect} ", rect);
IsArrangeValid = true; IsArrangeValid = true;
ArrangeCore(rect); ArrangeCore(rect);
@ -378,7 +378,7 @@ namespace Avalonia.Layout
{ {
if (IsMeasureValid) if (IsMeasureValid)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Layout, this, "Invalidated measure"); Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Invalidated measure");
IsMeasureValid = false; IsMeasureValid = false;
IsArrangeValid = false; IsArrangeValid = false;
@ -399,7 +399,7 @@ namespace Avalonia.Layout
{ {
if (IsArrangeValid) if (IsArrangeValid)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Layout, this, "Invalidated arrange"); Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Invalidated arrange");
IsArrangeValid = false; IsArrangeValid = false;
(VisualRoot as ILayoutRoot)?.LayoutManager?.InvalidateArrange(this); (VisualRoot as ILayoutRoot)?.LayoutManager?.InvalidateArrange(this);

2
src/Avalonia.Logging.Serilog/SerilogLogger.cs

@ -31,7 +31,7 @@ namespace Avalonia.Logging.Serilog
Logger.Sink = new SerilogLogger(output); Logger.Sink = new SerilogLogger(output);
} }
public bool IsEnabled(LogEventLevel level) public bool IsEnabled(LogEventLevel level, string area)
{ {
return _output.IsEnabled((SerilogLogEventLevel)level); return _output.IsEnabled((SerilogLogEventLevel)level);
} }

2
src/Avalonia.OpenGL/EglGlPlatformFeature.cs

@ -34,7 +34,7 @@ namespace Avalonia.OpenGL
} }
catch(Exception e) catch(Exception e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", null, "Unable to initialize EGL-based rendering: {0}", e); Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log(null, "Unable to initialize EGL-based rendering: {0}", e);
return null; return null;
} }
} }

8
src/Avalonia.OpenGL/OpenGlControlBase.cs

@ -94,7 +94,7 @@ namespace Avalonia.OpenGL
} }
catch (Exception e) catch (Exception e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", "OpenGlControlBase", Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
"Unable to initialize OpenGL: unable to create additional OpenGL context: {exception}", e); "Unable to initialize OpenGL: unable to create additional OpenGL context: {exception}", e);
_glFailed = true; _glFailed = true;
return false; return false;
@ -109,7 +109,7 @@ namespace Avalonia.OpenGL
{ {
_context.Dispose(); _context.Dispose();
_context = null; _context = null;
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", "OpenGlControlBase", Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
"Unable to initialize OpenGL: unable to create OpenGlTextureBitmap: {exception}", e); "Unable to initialize OpenGL: unable to create OpenGlTextureBitmap: {exception}", e);
_glFailed = true; _glFailed = true;
return false; return false;
@ -138,7 +138,7 @@ namespace Avalonia.OpenGL
{ {
int code; int code;
while ((code = gl.GetError()) != 0) while ((code = gl.GetError()) != 0)
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", "OpenGlControlBase", Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
"Unable to initialize OpenGL FBO: {code}", code); "Unable to initialize OpenGL FBO: {code}", code);
_glFailed = true; _glFailed = true;
@ -147,7 +147,7 @@ namespace Avalonia.OpenGL
} }
catch(Exception e) catch(Exception e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", "OpenGlControlBase", Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
"Unable to initialize OpenGL FBO: {exception}", e); "Unable to initialize OpenGL FBO: {exception}", e);
_glFailed = true; _glFailed = true;
} }

3
src/Avalonia.Styling/StyledElement.cs

@ -689,8 +689,7 @@ namespace Avalonia
#if DEBUG #if DEBUG
if (((INotifyCollectionChangedDebug)Classes).GetCollectionChangedSubscribers()?.Length > 0) if (((INotifyCollectionChangedDebug)Classes).GetCollectionChangedSubscribers()?.Length > 0)
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Control)?.Log(
LogArea.Control,
this, this,
"{Type} detached from logical tree but still has class listeners", "{Type} detached from logical tree but still has class listeners",
GetType()); GetType());

6
src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs

@ -65,15 +65,13 @@ namespace Avalonia.Animation.Animators
} }
} }
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Animations)?.Log(
LogArea.Animations,
control, control,
$"Cannot find the appropriate transform: \"{Property.OwnerType}\" in {control}."); $"Cannot find the appropriate transform: \"{Property.OwnerType}\" in {control}.");
} }
else else
{ {
Logger.TryGet(LogEventLevel.Error)?.Log( Logger.TryGet(LogEventLevel.Error, LogArea.Animations)?.Log(
LogArea.Animations,
control, control,
$"Cannot apply animation: Target property owner {Property.OwnerType} is not a Transform object."); $"Cannot apply animation: Target property owner {Property.OwnerType} is not a Transform object.");
} }

2
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

@ -287,7 +287,7 @@ namespace Avalonia.Rendering
} }
catch (RenderTargetCorruptedException ex) catch (RenderTargetCorruptedException ex)
{ {
Logger.TryGet(LogEventLevel.Information)?.Log("Renderer", this, "Render target was corrupted. Exception: {0}", ex); Logger.TryGet(LogEventLevel.Information, LogArea.Animations)?.Log(this, "Render target was corrupted. Exception: {0}", ex);
RenderTarget?.Dispose(); RenderTarget?.Dispose();
RenderTarget = null; RenderTarget = null;
} }

2
src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs

@ -78,7 +78,7 @@ namespace Avalonia.Rendering
} }
catch (RenderTargetCorruptedException ex) catch (RenderTargetCorruptedException ex)
{ {
Logger.TryGet(LogEventLevel.Information)?.Log("Renderer", this, "Render target was corrupted. Exception: {0}", ex); Logger.TryGet(LogEventLevel.Information, LogArea.Animations)?.Log(this, "Render target was corrupted. Exception: {0}", ex);
_renderTarget.Dispose(); _renderTarget.Dispose();
_renderTarget = null; _renderTarget = null;
} }

4
src/Avalonia.Visuals/Rendering/RenderLoop.cs

@ -120,7 +120,7 @@ namespace Avalonia.Rendering
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log(LogArea.Visual, this, "Exception in render update: {Error}", ex); Logger.TryGet(LogEventLevel.Error, LogArea.Visual)?.Log(this, "Exception in render update: {Error}", ex);
} }
} }
} }
@ -136,7 +136,7 @@ namespace Avalonia.Rendering
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log(LogArea.Visual, this, "Exception in render loop: {Error}", ex); Logger.TryGet(LogEventLevel.Error, LogArea.Visual)?.Log(this, "Exception in render loop: {Error}", ex);
} }
finally finally
{ {

7
src/Avalonia.Visuals/Visual.cs

@ -387,7 +387,7 @@ namespace Avalonia
/// <param name="e">The event args.</param> /// <param name="e">The event args.</param>
protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e) protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Visual, this, "Attached to visual tree"); Logger.TryGet(LogEventLevel.Verbose, LogArea.Visual)?.Log(this, "Attached to visual tree");
_visualRoot = e.Root; _visualRoot = e.Root;
@ -424,7 +424,7 @@ namespace Avalonia
/// <param name="e">The event args.</param> /// <param name="e">The event args.</param>
protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e) protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
{ {
Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Visual, this, "Detached from visual tree"); Logger.TryGet(LogEventLevel.Verbose, LogArea.Visual)?.Log(this, "Detached from visual tree");
_visualRoot = null; _visualRoot = null;
@ -501,8 +501,7 @@ namespace Avalonia
return; return;
} }
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Binding)?.Log(
LogArea.Binding,
this, this,
"Error in binding to {Target}.{Property}: {Message}", "Error in binding to {Target}.{Property}: {Message}",
this, this,

2
src/Avalonia.X11/Glx/GlxPlatformFeature.cs

@ -37,7 +37,7 @@ namespace Avalonia.X11.Glx
} }
catch(Exception e) catch(Exception e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log("OpenGL", null, "Unable to initialize GLX-based rendering: {0}", e); Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log(null, "Unable to initialize GLX-based rendering: {0}", e);
return null; return null;
} }
} }

3
src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs

@ -39,8 +39,7 @@ namespace Avalonia.Markup.Xaml.Converters
!property.IsAttached && !property.IsAttached &&
!registry.IsRegistered(targetType, property)) !registry.IsRegistered(targetType, property))
{ {
Logger.TryGet(LogEventLevel.Warning)?.Log( Logger.TryGet(LogEventLevel.Warning, LogArea.Property)?.Log(
LogArea.Property,
this, this,
"Property '{Owner}.{Name}' is not registered on '{Type}'.", "Property '{Owner}.{Name}' is not registered on '{Type}'.",
effectiveOwner, effectiveOwner,

3
src/Markup/Avalonia.Markup/Markup/Data/DelayedBinding.cs

@ -147,8 +147,7 @@ namespace Avalonia.Markup.Data
} }
catch (Exception e) catch (Exception e)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log( Logger.TryGet(LogEventLevel.Error, LogArea.Property)?.Log(
LogArea.Property,
control, control,
"Error setting {Property} on {Target}: {Exception}", "Error setting {Property} on {Target}: {Exception}",
Property.Name, Property.Name,

3
src/Windows/Avalonia.Direct2D1/Media/StreamGeometryContextImpl.cs

@ -82,8 +82,7 @@ namespace Avalonia.Direct2D1.Media
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.TryGet(LogEventLevel.Error)?.Log( Logger.TryGet(LogEventLevel.Error, LogArea.Visual)?.Log(
LogArea.Visual,
this, this,
"GeometrySink.Close exception: {Exception}", "GeometrySink.Close exception: {Exception}",
ex); ex);

2
tests/Avalonia.UnitTests/TestLogSink.cs

@ -27,7 +27,7 @@ namespace Avalonia.UnitTests
return Disposable.Create(() => Logger.Sink = null); return Disposable.Create(() => Logger.Sink = null);
} }
public bool IsEnabled(LogEventLevel level) public bool IsEnabled(LogEventLevel level, string area)
{ {
return true; return true;
} }

Loading…
Cancel
Save