// runs the operation... public async Task RunAsync(IBackgroundTaskInstance instance) { // configure the logging system to use a streaming target... try { LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget()); } catch { // no-op... waiting for a change in MetroLog to see if the config // has already been done... } // logging is a bit tricky as we have to gather all of the messages // and flush them out... var logTasks = new List <Task <LogWriteOperation[]> >(); // do some logging... var asyncLogger = (ILoggerAsync)this.Logger; logTasks.Add(asyncLogger.InfoAsync("Started background task '{0}' (#{1})...", instance.Task.Name, instance.Task.TaskId)); // run... try { // start the app... await StreetFooRuntime.Start("Tasks"); // defer... await DoRunAsync(instance); } catch (Exception ex) { logTasks.Add(asyncLogger.FatalAsync(string.Format("Background task '{0}' (#{1}) failed.", instance.Task.Name, instance.Task.TaskId), ex)); } // finish... logTasks.Add(asyncLogger.InfoAsync("Finished background task '{0}' (#{1}).", instance.Task.Name, instance.Task.TaskId)); // wait... await Task.WhenAll(logTasks); }