/// <summary> /// Sends the value provided by the provided delegate, only if Error is enabled. /// </summary> /// <typeparam name="T">The type of object we are logging about.</typeparam> /// <param name="logger">The logger to use.</param> /// <param name="function">The function to evaluate if Error logging is enabled.</param> public static void Error <T>(this IFullLogger logger, Func <string> function) { if (logger.IsErrorEnabled) { logger.Error <T>(function.Invoke()); } }
public static IObservable <IChangeSet <TSource, TKey> > CacheChangeSet <TSource, TKey>( this IObservable <IChangeSet <TSource, TKey> > source, string cacheKey, IBlobCache?blobCache = null, IFullLogger?log = default) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (cacheKey == null) { throw new ArgumentNullException(nameof(cacheKey)); } blobCache ??= BlobCache.LocalMachine; return(Observable .Create <IChangeSet <TSource, TKey> >(observer => source .ToCollection() .Concat( blobCache .GetObject <List <TSource> >(cacheKey) .Catch(Observable.Return(new List <TSource>()))) .Subscribe(items => { log?.Debug("CACHE: Writing {Count} items to cache with key: {CacheKey}", items.Count, cacheKey); blobCache .InsertObject(cacheKey, items.ToList()) .Catch(Observable.Return(Unit.Default).Do(unit => log?.Error("Failed to add items to cache"))); }))); }
public ModsViewModel(IScreen screen, DowModLoader?dowModService = null) : base(screen, "mods") { this.logger = this.Log(); this.dowModService = dowModService ?? Locator.Current.GetService <DowModLoader>(); var whenNotLoading = this.WhenAnyValue(x => x.Loading).Select(loading => !loading).DistinctUntilChanged(); var whenItemSelected = this.WhenAnyValue(x => x.SelectedBaseItem, x => x.SelectedModItem, (baseItem, modItem) => baseItem != null || modItem != null).DistinctUntilChanged(); var canLoadSpecific = whenNotLoading.CombineLatest(whenItemSelected, (notLoading, itemSelected) => notLoading && itemSelected).DistinctUntilChanged(); ReloadMods = ReactiveCommand.CreateFromTask(LoadAllMods, whenNotLoading); RefreshMods = ReactiveCommand.CreateFromTask(GetModsAsync); RefreshMods.ThrownExceptions.Subscribe(exception => logger.Error(exception)); RefreshMods.Execute().Subscribe(); RefreshMods.Select(mods => mods.Where(x => !x.Module.File.IsVanilla)) .Subscribe(mods => { ModItems.Clear(); ModItems.AddRange(mods); }); RefreshMods.Select(mods => mods.Where(x => x.Module.File.IsVanilla)) .Subscribe(mods => { BaseGameItems.Clear(); BaseGameItems.AddRange(mods); }); }
/// <summary> /// Sends the value provided by the provided delegate, only if Error is enabled. /// </summary> /// <typeparam name="T">The type of object we are logging about.</typeparam> /// <param name="logger">The logger to use.</param> /// <param name="function">The function to evaluate if Error logging is enabled.</param> public static void Error <T>(this IFullLogger logger, Func <string> function) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (function is null) { throw new ArgumentNullException(nameof(function)); } if (logger.IsErrorEnabled) { logger.Error <T>(function.Invoke()); } }
public static void LogForType(this IFullLogger logger, NotificationType notificationType, string message) { switch (notificationType) { case NotificationType.Info: logger.Info(message); break; case NotificationType.Warning: logger.Warn(message); break; case NotificationType.Error: logger.Error(message); break; } }