Browse Source

Fix missing logging.

refactor/style-priorities
Steven Kirk 4 years ago
parent
commit
88d59a4ed5
  1. 1
      src/Avalonia.Base/PropertyStore/BindingEntry.cs
  2. 1
      src/Avalonia.Base/PropertyStore/LocalValueUntypedBindingObserver.cs
  3. 24
      src/Avalonia.Base/PropertyStore/LoggingUtils.cs
  4. 1
      src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs
  5. 10
      tests/Avalonia.Base.UnitTests/VisualTests.cs

1
src/Avalonia.Base/PropertyStore/BindingEntry.cs

@ -89,6 +89,7 @@ namespace Avalonia.PropertyStore
if (value is BindingNotification n)
{
value = n.Value;
LoggingUtils.LogIfNecessary(_frame.Owner.Owner, Property, n);
}
if (value == AvaloniaProperty.UnsetValue)

1
src/Avalonia.Base/PropertyStore/LocalValueUntypedBindingObserver.cs

@ -37,6 +37,7 @@ namespace Avalonia.PropertyStore
if (value is BindingNotification n)
{
value = n.Value;
LoggingUtils.LogIfNecessary(_owner.Owner, Property, n);
}
if (value == AvaloniaProperty.UnsetValue)

24
src/Avalonia.Base/PropertyStore/LoggingUtils.cs

@ -1,12 +1,21 @@
using System;
using System.Runtime.CompilerServices;
using Avalonia.Data;
using Avalonia.Logging;
namespace Avalonia.PropertyStore
{
internal static class LoggingUtils
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogIfNecessary(
AvaloniaObject owner,
AvaloniaProperty property,
BindingNotification value)
{
if (value.ErrorType != BindingErrorType.None)
Log(owner, property, value.Error!);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogIfNecessary<T>(
AvaloniaObject owner,
@ -45,6 +54,19 @@ namespace Avalonia.PropertyStore
}
}
private static void Log(
AvaloniaObject owner,
AvaloniaProperty property,
Exception e)
{
owner.GetBindingWarningLogger(property, e)?.Log(
owner,
"Error in binding to {Target}.{Property}: {Message}",
owner,
property,
e.Message);
}
private static void Log<T>(
AvaloniaObject owner,
AvaloniaProperty property,

1
src/Avalonia.Base/PropertyStore/UntypedBindingEntry.cs

@ -113,6 +113,7 @@ namespace Avalonia.PropertyStore
if (value is BindingNotification n)
{
value = n.Value;
LoggingUtils.LogIfNecessary(_frame.Owner.Owner, Property, n);
}
if (value == AvaloniaProperty.UnsetValue)

10
tests/Avalonia.Base.UnitTests/VisualTests.cs

@ -281,13 +281,17 @@ namespace Avalonia.Base.UnitTests
{
var target = new Decorator();
var root = new TestRoot { Child = target, DataContext = "foo" };
var called = false;
var called = 0;
LogCallback checkLogMessage = (level, area, src, mt, pv) =>
{
if (level >= Avalonia.Logging.LogEventLevel.Warning)
{
called = true;
Assert.Equal("Error in binding to {Target}.{Property}: {Message}", mt);
Assert.Same(target, pv[0]);
Assert.Equal(Decorator.TagProperty, pv[1]);
Assert.Equal("Could not find a matching property accessor for 'Foo' on 'foo'", pv[2]);
++called;
}
};
@ -296,7 +300,7 @@ namespace Avalonia.Base.UnitTests
target.Bind(Decorator.TagProperty, new Binding("Foo"));
}
Assert.True(called);
Assert.Equal(1, called);
}
[Fact]

Loading…
Cancel
Save