[C] Expose Application.LogWarningsListener (#4539) fixes #1517 fixes #3873
authorStephane Delcroix <stephane@delcroix.org>
Mon, 3 Dec 2018 12:59:52 +0000 (13:59 +0100)
committerRui Marinho <me@ruimarinho.net>
Mon, 3 Dec 2018 12:59:52 +0000 (12:59 +0000)
* [C] Expose Application.LogWarningsListener

The fix proposed in #2911 didn't worked with Release build of XF, aka
the majority of the builds used.
This fix allows the developer to set any logger he might like, but the
plan is to add a default one in the template, that uses Debug.WriteLine,
so it will Log if the user application is build with Debug, and not if
XF binaries are.

- fixes #1517
- fixes #3873

* Update Xamarin.Forms.Core/BindableObject.cs

* Update Xamarin.Forms.Core/ListView.cs

Xamarin.Forms.Core/Application.cs
Xamarin.Forms.Core/BindableObject.cs
Xamarin.Forms.Core/ListView.cs

index 8710101..aee45b4 100644 (file)
@@ -24,35 +24,10 @@ namespace Xamarin.Forms
 
                static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
 
-               static Lazy<DelegateLogListener> _applicationOutputListener;
-               static bool _logWarningsToApplicationOutput;
-
-               public static bool LogWarningsToApplicationOutput
-               {
-                       get => _logWarningsToApplicationOutput;
-                       set
-                       {
-                               _logWarningsToApplicationOutput = value;
-
-                               if (_logWarningsToApplicationOutput)
-                               {
-                                       if (!Log.Listeners.Contains(_applicationOutputListener.Value))
-                                       {
-                                               Log.Listeners.Add(_applicationOutputListener.Value);
-                                       }
-                               }
-                               else
-                               {
-                                       if (Log.Listeners.Contains(_applicationOutputListener.Value))
-                                       {
-                                               Log.Listeners.Remove(_applicationOutputListener.Value);
-                                       }
-                               }
-                       }
-               }
+               [Obsolete("Assign the LogWarningsListener")]
+               public static bool LogWarningsToApplicationOutput { get; set; }
 
                bool MainPageSet { get; set; }
-               
 
                public Application()
                {
@@ -65,10 +40,6 @@ namespace Xamarin.Forms
                        SystemResources = DependencyService.Get<ISystemResourcesProvider>().GetSystemResources();
                        SystemResources.ValuesChanged += OnParentResourcesChanged;
                        _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
-                       _applicationOutputListener = new Lazy<DelegateLogListener>(() => new DelegateLogListener((arg1, arg2) =>
-                       {
-                               Debug.WriteLine($"{arg1}: {arg2}");
-                       }));
                }
 
                public void Quit()
index 38385fb..a43a2f4 100644 (file)
@@ -376,10 +376,10 @@ namespace Xamarin.Forms
                        bool converted = (privateAttributes & SetValuePrivateFlags.Converted) != 0;
 
                        if (property == null)
-                               throw new ArgumentNullException("property");
+                               throw new ArgumentNullException(nameof(property));
                        if (checkAccess && property.IsReadOnly)
                        {
-                               Debug.WriteLine("Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName);
+                               Log.Warning("BindableObject", "Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName);
                                return;
                        }
 
index de8ddbe..ca13af1 100644 (file)
@@ -506,7 +506,7 @@ namespace Xamarin.Forms
                        if (newValue != null && lv.GroupDisplayBinding != null)
                        {
                                lv.GroupDisplayBinding = null;
-                               Debug.WriteLine("GroupHeaderTemplate and GroupDisplayBinding can not be set at the same time, setting GroupDisplayBinding to null");
+                               Log.Warning("ListView", "GroupHeaderTemplate and GroupDisplayBinding can not be set at the same time, setting GroupDisplayBinding to null");
                        }
                }
 
@@ -623,4 +623,4 @@ namespace Xamarin.Forms
                        return true;
                }
        }
-}
\ No newline at end of file
+}