public async Task <IEntry <TwitterContact> > FetchAsync(ulong id) { try { var user = await _client.GetUserAsync(id); return(_entryFactory.Create( new TwitterContact( ((ulong?)user.Id).GetValueOrDefault(id), user.Name, user.ScreenName, $"https://twitter.com/{user.ScreenName}" ) )); } catch (TwitterException e) { if (e.Status == HttpStatusCode.NotFound) { throw new ContactNotFoundException <TwitterContact>(e); } throw; } }
public async Task <IEntry <GitHubContact> > FetchAsync(ulong id) { try { return(_entryFactory.Create( await _client.GetAsync <GitHubContact>($"user/{id}") )); } catch (GitHubException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { throw new ContactNotFoundException <GitHubContact>(e); } throw; } }
public async Task <IEntry <DiscordContact> > FetchAsync(ulong id) { var user = await _client.GetUserAsync(id); if (user is null) { throw new ContactNotFoundException <DiscordContact>(null); } return(_entryFactory.Create( new DiscordContact( user.Id, user.Username, user.Discriminator, null ) )); }
/// <summary> /// Method called by the logging framework to persist the log /// </summary> /// <typeparam name="TState">Type of the logger state</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/> being logged</param> /// <param name="eventId">The <see cref="EventId"/> being logged</param> /// <param name="state">The state being logged</param> /// <param name="exception">The <see cref="Exception"/> being logged</param> /// <param name="formatter">The formatter used to create the message being logged</param> public virtual void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } var message = formatter(state, exception) ?? ""; if (!string.IsNullOrWhiteSpace(message) || exception != null) { ScopeProvider?.ForEachScope <object>((scope, _) => message += Environment.NewLine + scope, null); var entry = _entryFactory.Create(Name, logLevel, eventId, state, exception, message); QueueEntry(entry); } }