private void LogError(Task task, object state) { if (_logger == null) { // observe the task exception when no UI logger provided. Trace.WriteLine(ExceptionUtilities.DisplayMessage(task.Exception)); return; } // UI logger only can be engaged from the main thread MonoDevelop.Core.Runtime.RunInMainThread(() => { var errorMessage = ExceptionUtilities.DisplayMessage(task.Exception); _logger.Log( ProjectManagement.MessageLevel.Error, $"[{state.ToString()}] {errorMessage}"); }); }
private void LogError(Task task, object state) { if (_logger == null) { // observe the task exception when no UI logger provided. Trace.WriteLine(ExceptionUtilities.DisplayMessage(task.Exception)); return; } // UI logger only can be engaged from the main thread NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async () => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var errorMessage = ExceptionUtilities.DisplayMessage(task.Exception); _logger.Log( ProjectManagement.MessageLevel.Error, $"[{state.ToString()}] {errorMessage}"); }); }
public void Log(ProjectManagement.MessageLevel level, string message, params object[] args) { _logger.Log(level, message, args); }
private void LoadItems(PackageItemListViewModel selectedPackageItem, CancellationToken token) { // If there is another async loading process - cancel it. var loadCts = CancellationTokenSource.CreateLinkedTokenSource(token); Interlocked.Exchange(ref _loadCts, loadCts)?.Cancel(); var currentLoader = _loader; _joinableTaskFactory.Value.RunAsync(async() => { await TaskScheduler.Default; var addedLoadingIndicator = false; try { // add Loading... indicator if not present if (!Items.Contains(_loadingStatusIndicator)) { Items.Add(_loadingStatusIndicator); addedLoadingIndicator = true; } await LoadItemsCoreAsync(currentLoader, loadCts.Token); await _joinableTaskFactory.Value.SwitchToMainThreadAsync(); if (selectedPackageItem != null) { UpdateSelectedItem(selectedPackageItem); } } catch (OperationCanceledException) when(!loadCts.IsCancellationRequested) { loadCts.Cancel(); loadCts.Dispose(); currentLoader.Reset(); await _joinableTaskFactory.Value.SwitchToMainThreadAsync(); // The user cancelled the login, but treat as a load error in UI // So the retry button and message is displayed // Do not log to the activity log, since it is not a NuGet error _logger.Log(ProjectManagement.MessageLevel.Error, Resx.Resources.Text_UserCanceled); _loadingStatusIndicator.SetError(Resx.Resources.Text_UserCanceled); _loadingStatusBar.SetCancelled(); _loadingStatusBar.Visibility = Visibility.Visible; } catch (Exception ex) when(!loadCts.IsCancellationRequested) { loadCts.Cancel(); loadCts.Dispose(); currentLoader.Reset(); // Write stack to activity log Mvs.ActivityLog.LogError(LogEntrySource, ex.ToString()); await _joinableTaskFactory.Value.SwitchToMainThreadAsync(); var errorMessage = ExceptionUtilities.DisplayMessage(ex); _logger.Log(ProjectManagement.MessageLevel.Error, errorMessage); _loadingStatusIndicator.SetError(errorMessage); _loadingStatusBar.SetError(); _loadingStatusBar.Visibility = Visibility.Visible; } finally { if (_loadingStatusIndicator.Status != LoadingStatus.NoItemsFound && _loadingStatusIndicator.Status != LoadingStatus.ErrorOccurred) { // Ideally, After a serach, it should report its status and, // do not keep the LoadingStatus.Loading forever. // This is a workaround. var emptyListCount = addedLoadingIndicator ? 1 : 0; if (Items.Count == emptyListCount) { _loadingStatusIndicator.Status = LoadingStatus.NoItemsFound; } else { Items.Remove(_loadingStatusIndicator); } } } UpdateCheckBoxStatus(); LoadItemsCompleted?.Invoke(this, EventArgs.Empty); }); }
private void LoadItems(PackageItemListViewModel selectedPackageItem) { var loadCts = new CancellationTokenSource(); // If there is another async loading process - cancel it. Interlocked.Exchange(ref _loadCts, loadCts)?.Cancel(); var currentLoader = _loader; NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() => { await TaskScheduler.Default; try { await LoadItemsCoreAsync(currentLoader, loadCts.Token); await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (selectedPackageItem != null) { UpdateSelectedItem(selectedPackageItem); } } catch (OperationCanceledException) when(!loadCts.IsCancellationRequested) { loadCts.Cancel(); currentLoader.Reset(); await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // The user cancelled the login, but treat as a load error in UI // So the retry button and message is displayed // Do not log to the activity log, since it is not a NuGet error _logger.Log(ProjectManagement.MessageLevel.Error, Resx.Resources.Text_UserCanceled); _loadingStatusIndicator.SetError(Resx.Resources.Text_UserCanceled); _loadingStatusBar.SetCancelled(); _loadingStatusBar.Visibility = Visibility.Visible; } catch (Exception ex) when(!loadCts.IsCancellationRequested) { loadCts.Cancel(); currentLoader.Reset(); // Write stack to activity log Mvs.ActivityLog.LogError(LogEntrySource, ex.ToString()); await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var errorMessage = ExceptionUtilities.DisplayMessage(ex); _logger.Log(ProjectManagement.MessageLevel.Error, errorMessage); _loadingStatusIndicator.SetError(errorMessage); _loadingStatusBar.SetError(); _loadingStatusBar.Visibility = Visibility.Visible; } UpdateCheckBoxStatus(); }); }
private void LogError(string message) { _outputConsoleLogger.Log(MessageLevel.Error, message); }
private void LogError(string message) { _outputConsoleLogger.Log(new LogMessage(LogLevel.Error, message)); }
public void Log(ProjectManagement.MessageLevel level, string message, params object[] args) { _logger.Log(new LogMessage(level.ToLogLevel(), string.Format(CultureInfo.CurrentCulture, message, args))); }
public void Log(MessageLevel level, string message, params object[] args) { _logger.Log(level, message, args); }