Commit 2c4b0652 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added sample LoggingService printing in both Android logcat and Visual Studio console

parent 3ca5292f
......@@ -52,7 +52,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
......
......@@ -4,6 +4,10 @@ using System.Threading;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#if ANDROID
using Android.Util;
#endif
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace Xamarin
{
......@@ -19,7 +23,8 @@ namespace Xamarin
LinphoneWrapper.setNativeLogHandler();
Factory.Instance.EnableLogCollection(LogCollectionState.Enabled);
LoggingService.Instance.Listener.OnLogMessageWritten = OnLog;
CoreListener listener = Factory.Instance.CreateCoreListener();
listener.OnGlobalStateChanged = OnGlobal;
#if ANDROID
......@@ -38,6 +43,49 @@ namespace Xamarin
return MainPage.FindByName<StackLayout>("stack_layout");
}
private void OnLog(LoggingService logService, string domain, LogLevel lev, string message)
{
string now = DateTime.Now.ToString("hh:mm:ss");
string log = now + " [";
switch (lev)
{
case LogLevel.Debug:
log += "DEBUG";
#if ANDROID
Log.Debug(domain, message);
#endif
break;
case LogLevel.Error:
log += "ERROR";
#if ANDROID
Log.Error(domain, message);
#endif
break;
case LogLevel.Message:
log += "MESSAGE";
#if ANDROID
Log.Info(domain, message);
#endif
break;
case LogLevel.Warning:
log += "WARNING";
#if ANDROID
Log.Warn(domain, message);
#endif
break;
case LogLevel.Fatal:
log += "FATAL";
#if ANDROID
Log.Error(domain, message);
#endif
break;
default:
break;
}
log += "] (" + domain + ") " + message;
Console.WriteLine(log);
}
private void OnGlobal(Core lc, GlobalState gstate, string message)
{
Console.WriteLine("Global state changed: " + gstate);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment