﻿extern alias pcl;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace MetroLog
{
    public static class GlobalCrashHandler
    {
        public static void Configure()
        {
            Application.Current.UnhandledException += App_UnhandledException;
        }

        private static async void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // unbind we're going to re-enter and don't want to loop...
            Application.Current.UnhandledException -= App_UnhandledException;

            // say we've handled this one. this allows our FATAL write to complete.
            e.Handled = true;

            // go...
            var log = (ILoggerAsync)pcl::MetroLog.LogManagerFactory.DefaultLogManager.GetLogger<Application>();
            await log.FatalAsync("The application crashed: " + e.Message, e.Exception);

            // if we're aborting, fake a suspend to flush the targets...
            await LazyFlushManager.FlushAllAsync(new LogWriteContext());

            // abort the app here...
            Application.Current.Exit();
        }
    }
}

﻿extern alias pcl;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace MetroLog
{
    public static class GlobalCrashHandler
    {
        public static void Configure()
        {
            Application.Current.UnhandledException += App_UnhandledException;
        }

        private static async void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // unbind we're going to re-enter and don't want to loop...
            Application.Current.UnhandledException -= App_UnhandledException;

            // say we've handled this one. this allows our FATAL write to complete.
            e.Handled = true;

            // go...
            var log = (ILoggerAsync)pcl::MetroLog.LogManagerFactory.DefaultLogManager.GetLogger<Application>();
            await log.FatalAsync("The application crashed: " + e.Message, e);

            // if we're aborting, fake a suspend to flush the targets...
            await LazyFlushManager.FlushAllAsync(new LogWriteContext());

            // abort the app here...
            Application.Current.Exit();
        }
    }
}

Call correct overload of log.FatalAsync
Call correct overload of log.FatalAsync

The method was previously hitting `FatalSync(string message, params object[] args)` and thereby throwing away the exception object as it wasn't referenced in the message. The change ensures that `FatalSync(string message, Exception ex)` is hit and the exception information is logged correctly.